Unable to download a blob file with Firefox, but it works in Chrome?
Asked Answered
L

1

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.

Licketysplit answered 10/8, 2016 at 9:26 Comment(1)
According to this : stackoverflow.com/a/30708820, a wait needs to be added before revoking the URL. It worked for me.Licketysplit
D
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);
Dissyllable answered 4/10, 2017 at 18:23 Comment(1)
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://<Ip address>/4c3d3e21-f443-7449-a96f-61c7f94f7570 (“frame-src”).Shellans

© 2022 - 2024 — McMap. All rights reserved.