3

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.

  • Possible duplicate of [Open links made by createObjectURL in IE11](https://stackoverflow.com/questions/24007073/open-links-made-by-createobjecturl-in-ie11) – BlueWater86 Jan 25 '19 at 11:39
  • 1
    @BlueWater86 This is talking about Edge on iOS, which uses Apple's rendering engine. IE or Desktop Edge focused solutions will not work here. – Ben Collins Jan 28 '19 at 23:10

1 Answers1

2

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}
}
Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
  • 3
    This doesn't work on Edge iOS - it is built on Safari's engine and doesn't contain`window.navigator.msSaveOrOpenBlob` – Ben Collins Jan 28 '19 at 23:09