On some sites, when downloading a file, the file is " downloaded to the browser ", after the download has passed, the file is given to the browser already in the downloaded form. How does this happen? What kind of technology? And how to do this?
1 answer
These are new items, so be careful about compatibility.
XMLHttpRequest can return Blob as a result . Yes, the usual XHR:
var oReq = new XMLHttpRequest(); oReq.open("GET", "/myfile.png", true); oReq.responseType = "blob"; oReq.onload = function(oEvent) { var blob = oReq.response; // ^ вот этот Блоб }; oReq.send(); ... you can follow the progress of the download by specifying an onprogress handler.
From Blob and you can make the URL:
objectURL = URL.createObjectURL(blob); ... and give it to "download" in any way you like. Blob exists exclusively on the client, and if it exists, it is already entirely, so the “downloading” of the blob will in fact be preserving its already loaded content.
Blob can be formed in a huge number of ways, XHR is only one of them.
|
