10

Here is my download code:

var mimeType = this.getMime(obj);
var ab = this.base64ToArrayBuffer(obj[key]);
var blob = new Blob([ab.buffer], {
    type : mimeType
});
var result = this.bintostring(blob);
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = result.filename;
a.target = '_blank';
a.click();
window.URL.revokeObjectURL(url);

During debugging, I do not see any exceptions.

Sean Mickey
  • 7,618
  • 2
  • 32
  • 58
Avneesh
  • 145
  • 2
  • 2
  • 11
  • According to this : http://stackoverflow.com/a/30708820, a wait needs to be added before revoking the URL. It worked for me. – Avneesh Aug 10 '16 at 10:58

1 Answers1

13

For firefox appending the file to document has to be done. Firefox doesn't do it automatically unlike Chrome

a.download = result.filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
Sid Jonnala
  • 485
  • 4
  • 11
  • 2
    hi I am still getting the error in firefox but in chrome its working fine. I have added the anchor in my body as suggested above. Error details are as follows Content Security Policy: The page’s settings blocked the loading of a resource at blob:https:///4c3d3e21-f443-7449-a96f-61c7f94f7570 (“frame-src”). – Rahul Tokase Mar 18 '20 at 08:29