How to save a zip file with file name and extension in Safari 8 using jszip?
I want to save a file zip
on the client side using a library jszip
.
Here is my code:
function zipDownload(){
var fileName ="test.zip",
zip = new JSZip(),
content,
img,
data;
zip.file("hello.txt", "Hello World\n");
data = zip.generate({type: $.isFunction(window.Blob) ? "blob" : "base64"});
fileLoader.saveAs(fileName, "application/zip", data);
}
It works fine in all modern browsers except Safari 8.
Safari 8 cannot save file with file extension.
This is an example http://jsfiddle.net/uvhy34ar/3/ that shows this issue in action.
source to share
I faced the same problem. In my case, I was trying to save a file containing XML with a custom extension ( .cmf
). Safari 8 has always added an extension .xml
to mine. which results in myfile.cmf.xls
instead of myfile.cmf
.
The fix that worked for me was to set the server response header to
Content-Type: application/octet-stream
and Will! - the extension is not added anymore.
source to share