I'm trying to support downloading a file from an API in Edge on iOS. The file is downloaded as a blob, and we already have solutions in place for downloading on Safari and Chrome (Using createObjectUrl
and readAsDataUrl
respectively), but neither of these seem to work on Edge on iOS.
I can't find anything online around how to do this, and even FileReader doesn't seem to support it.
I have tried to download using solutions that work consistently in Chrome on iOS and Safari on iOS.
Edit: Edge on iOS uses Safari's rendering engine, so any IE11 or Edge on Desktop focused solutions will not work here.
In the IE/Edge browser, you could try to use window.navigator.msSaveOrOpenBlob method to download the file. You could check these article: thread 1 and article 1 . Code like this:
showFile(blob){
// It is necessary to create a new blob object with mime-type explicitly set
// otherwise only Chrome works like it should
var newBlob = new Blob([blob], {type: "application/pdf"})
// IE doesn't allow using a blob object directly as link href
// instead it is necessary to use msSaveOrOpenBlob
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
return;
}
// For other browsers:
// Create a link pointing to the ObjectURL containing the blob.
const data = window.URL.createObjectURL(newBlob);
var link = document.createElement('a');
link.href = data;
link.download="file.pdf";
link.click();
setTimeout(function(){
// For Firefox it is necessary to delay revoking the ObjectURL
window.URL.revokeObjectURL(data);
, 100}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.