Save or open blob with FileSaver.js on iOS Chrome and Safari
Asked Answered
D

1

11

I use docxtemplater library to create a docx document from javascript.

On desktop browsers, it works fine. On mobile, no problem on Android but i have some issue on iOS.

On iOS, when i try to download or open the document, a new tab is created in the browser when i can see an URL of type :

blob:http://mylocalServer/987788-3524-33iuhih3334434434

In this new tab, i can't see the document and i don't have any way to download it.

How can i have a solution to retrieve the docx document under iOS ?

Here is the code for creating the docx document in JS :

out=doc.getZip().generate({type:"blob"});
// Give a name for the output word document
var outputName = "test.docx" ;
saveAs(out,outputName);

saveAs function is called in FileSaver.js file :

And when the action is done on iOS, we are going throw this code :

fs_error = function() {
// don't create more object URLs than needed
if (blob_changed || !object_url) {
    object_url = get_URL().createObjectURL(blob);
}
if (target_view) {
    target_view.location.href = object_url;
} else {
    var new_tab = view.open(object_url, "_blank");
    if (new_tab == undefined && typeof safari !== "undefined") {
        //Apple do not allow window.open, see http://bit.ly/1kZffRI
        view.location.href = object_url
    }
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}
Dull answered 1/9, 2015 at 13:41 Comment(0)
C
0

Blob type should be set to application/vnd.openxmlformats-officedocument.wordprocessingml.document so Safari on iOS 11 and above can display the document and users may download it manually.

Cointreau answered 13/11, 2018 at 11:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.