Skip to content

Commit c0c13cc

Browse files
author
Antelle
committed
Workaround for downloading application/octet-stream in Safari
1 parent bf44e18 commit c0c13cc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

FileSaver.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ var saveAs = saveAs || (function(view) {
9494
}
9595
// on any filesys errors revert to saving with object URLs
9696
, fs_error = function() {
97+
if (target_view && typeof safari !== "undefined" && typeof FileReader !== "undefined") {
98+
// Safari doesn't allow downloading of blob urls
99+
var reader = new FileReader();
100+
reader.onloadend = function() {
101+
var base64Data = reader.result;
102+
base64Data = base64Data.replace(/^data:.*;/, 'data:attachment/file;');
103+
target_view.location.href = encodeURI(base64Data);
104+
filesaver.readyState = filesaver.DONE;
105+
dispatch_all();
106+
};
107+
reader.readAsDataURL(blob);
108+
filesaver.readyState = filesaver.INIT;
109+
return;
110+
}
97111
// don't create more object URLs than needed
98112
if (blob_changed || !object_url) {
99113
object_url = get_URL().createObjectURL(blob);

0 commit comments

Comments
 (0)