简体   繁体   中英

Downloading image from blob in Firefox

I've tried implementing image download from blob by following the answer from this post (the one from @Jonathan Amend). The download function works perfectly in Google Chrome. However, upon testing it on Firefox, the file I end up getting is blob instead of jpg/png/etc. Is there any additional code necessary to make it work properly in Firefox? My code looks exactly the same in the ajax with the exception using atob on my data before passing it as new blob like so:

 var blob = new Blob([atob(data)], { type: type });

Not sure what's going on but for some strange reason, even if the type is set, the extension of the file does not get set in firefox. To fix this, I checked if browser is firefox and added the file type extension in the filename like so:

if(navigator.userAgent.search("Firefox") >- 1) {
     var temp = type.split('/');
     filename = filename + "." + temp[1];
}

Perhaps you suggest a better solution?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM