为什么我在Angularjs中使用JSZip压缩和下载CSV时出现CORS错误

时间:2018-11-27 08:15:14

标签: angularjs jszip

我正在使用JSZip进行Zip压缩,并从azure blob下载了超过5个CSV文件。

使用以下代码

FileArray-包含超过5个Blob网址以访问CSV

if(fileArray.length > 5) // Download the files as zip file if user selects more than 5 files to export
      {
        var zip = new JSZip();
        var zipFileName = "exportfiles.zip";
        var fileCount = 0;
        fileArray.forEach(function(files)
        {
          var fileName = files.fileName;
          **JSZipUtils.getBinaryContent**(files.downloadLink, function(err, data)
          {
            if(err) // If file not exists alert the user
            {
              alert("Error in downloading or File: "+ fileName + " doesn't exists");
              return false;
            }
            fileCount++;
            zip.file(fileName, data, {binary:true});
            if(fileCount === fileArray.length)
            {
              var zipFile = zip.generateAsync({type: "blob"})
              .then(function(content){
                saveAs(content, zipFileName);
              });
            }
          })
        });
      }

但是我收到“下载错误...”。

有帮助吗?

在控制台中:

无法加载https://dev-storage.test.com/tst-imports/mr/tes.csv

所请求的资源上没有“ Access-Control-Allow-Origin”标头。因此,不允许访问来源“ https://ui.promaxoptimizedev.com”。

0 个答案:

没有答案