eligrey / FileSaver.js

An HTML5 saveAs() FileSaver implementation
https://eligrey.com/blog/saving-generated-files-on-the-client-side/
Other
21.58k stars 4.38k forks source link

SaveAs combination Worker Problems #713

Closed kayw-geek closed 3 years ago

kayw-geek commented 3 years ago

Problems Some of the downloaded image names are incorrect

image Mycode

 downloadMap() {
            var _this = this;
            var blobimgs = [];
            var workers = new Worker('/js/custom/worker/mapworker.js');
            for (var i = 0;i < _this.imgPaths.path.length;i++){
                filename =  _this.imgPaths.filename;            
                workers.postMessage([_this.imgPaths.path[i],_this.imgPaths.filename[i]])
            }
            workers.onmessage = function (e) {
                var res = e.data;
                console.log(res[1]);//It's also normal to print the content here
                saveAs(res[0],res[1]);
            }
          },
//mapworker.js
async function  fetchImg(path) {
    return await fetch(path,{
        mode: 'cors',
        headers: {
            'Access-Control-Allow-Origin':'*'
        },
    }).then(response => response.blob())
        .then(function(images){
            return images;
        })
}
addEventListener('message', function (e) {
    var data = e.data;
    var _this = this;
    _this.fetchImg(data[0]).then(res=>{
        _this.postMessage([res,data[1]])
   });
}, false);
kayw-geek commented 3 years ago

This is a problem with the browser. It seems that the processing speed can't catch up with that of the “worker”

jimmywarting commented 3 years ago

If you are downloading so many images then i think you should try zipping everything

kayw-geek commented 3 years ago

If you are downloading so many images then i think you should try zipping everything

I have used your other library to solve the problem perfectly. StreamSaver.js is really amazing. It’s "牛逼" in Chinese

jimmywarting commented 3 years ago

So can this issue be closed now then?