I need to download a large file with JavaScript using XMLHttpRequest or fetch without saving the file first in the RAM-Memory.
正常的链接下载对我来说是徒劳的,因为我需要向请求的负责人寄出一个“灯塔”。
I could manage to download a file, but this "solution", it s saving the file first in the RAM-Memory, before I get a save dialog, so that the Browser will brake if the file is larger then the available RAM-Memory.
我的“孤独”是指:
var myHeaders = new Headers();
myHeaders.append( Authorization , `Bearer ${token}`);
var myInit = { method: GET ,
headers: myHeaders,
mode: cors ,
cache: default };
var a = document.createElement( a );
fetch(url,myInit)
.then((response)=> {
return response.blob();
})
.then((myBlob)=> {
a.href = window.URL.createObjectURL(myBlob);
var attr = document.createAttribute("download");
a.setAttributeNode(attr);
a.style.display = none ;
document.body.appendChild(a);
a.click();
a.remove();
});
这里是我与XMLHttpRequest的“团结”:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = ()=>{
if (xhttp.readyState == 4){
if ((xhttp.status == 200) || (xhttp.status == 0)){
var a = document.createElement( a );
a.href = window.URL.createObjectURL(xhttp.response); // xhr.response is a blob
var attr = document.createAttribute("download");
a.setAttributeNode(attr);
a.style.display = none ;
document.body.appendChild(a);
a.click();
a.remove();
}
}
};
xhttp.open("GET", url);
xhttp.responseType = "blob";
xhttp.setRequestHeader( Authorization , `Bearer ${token}`);
xhttp.send();
问题是,我如何下载更多的文件,然后下载现有的RAM-Memory,同时打上头盔?