reading an object URL produced in a worker with IE

对着背影说爱祢 提交于 2020-01-05 15:36:24

问题


I have a webworker that is producing a CSV for downloading, and to conserve memory I only have it return the URL it produces from teh blob.. My worker code looks something like::

var blob = new Blob([ResultOfSomeWork()],{type:'text/csv'});
URL.createObjectURL(blob);
self.postMessage({url:blob.url});

My goal is to just be able to download it in firefox and chrome this is very easy as I can just set up an invisible <a> and have it be clicked to download it.

For IE10 I want to use msSaveBlob but I need a blob which I don't want to transfer. How can I download a object dataurl in IE10?


回答1:


So I found a solution that works. Apparently, I can XHR and read the content back in my main thread.

worker.onmessage = function(event){
    var url = event.data.url;
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.responseType='blob';
    xhr.onload = function(){
       msSaveBlob(xhr.response, fileName +'.csv');
    };
    xhr.send();
}

While this feels extremely complicated it works well in practice and is really fast.



来源:https://stackoverflow.com/questions/29354491/reading-an-object-url-produced-in-a-worker-with-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!