angular-file-saver icon indicating copy to clipboard operation
angular-file-saver copied to clipboard

Downloading files does not work properly on iOS

Open arjanvlek opened this issue 9 years ago • 13 comments

Downloading a file does not work properly on iOS 7.1.2 and iOS 9.1. A new window is opened with blob:// in the address bar. In case of a binary file, a blank page is displayed (while an Open with Excel button is present and does work) but no file preview is generated.

Text files (like CSV) are displayed as-is and are not prompted to download. There is also no "Open with" button available for these file types.

Is there a fix available or do I need to bypass this with a user agent check and use another downloading method on iOS?

Versions: Angular-file-saver: 1.0.1 iOS versions 9.1 and 7.1.2 face this issue, I assume all versions between also share this issue.

arjanvlek avatar Dec 01 '15 08:12 arjanvlek

Unfortunately, it's a known FileSaver.js issue: https://github.com/eligrey/FileSaver.js/issues/179

alferov avatar Dec 01 '15 14:12 alferov

And what's the solution to the FileSaver.js issue?

arjanvlek avatar Dec 09 '15 09:12 arjanvlek

There was a large update that affected iOS: https://github.com/eligrey/FileSaver.js/commit/c0c13ccc0e2e7b714e519c1890bec9ecbaaaf75e I'll try to roll back and test it.

alferov avatar Dec 15 '15 02:12 alferov

Is there any updates about this?

I am trying to export an Excel file and it works fine with Chrome, IE and Firefox. But Safari just opens an empty tab where I cannot for example just save the content.

The demo opens a new tab with blob: in the address bar.

Hypocrite avatar Feb 25 '16 09:02 Hypocrite

You should use window.open (JavaScript) or <a href... (HTML) on the binary file URL that is generated from your backend. That way it works on all browsers.

Op 25 feb. 2016 om 10:03 heeft Hypocrite [email protected] het volgende geschreven:

Is there any updates about this?

I am trying to export an Excel file and it works fine with Chrome, IE and Firefox. But Safari just opens an empty tab where I cannot for example just save the content.

The demo opens a new tab with blob: in the address bar.

— Reply to this email directly or view it on GitHub.

arjanvlek avatar Feb 25 '16 09:02 arjanvlek

Could you give an example? I currently have this code which is run with ng-click:

$scope.exportData = function () {
            var table = document.getElementById('exportable');
            var pagination = document.getElementById("results-footer").innerHTML = "";
            var blob = new Blob([table.innerHTML], {
                type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
            });
            FileSaver.saveAs(blob, 'Report.xls');
        };

Hypocrite avatar Feb 25 '16 10:02 Hypocrite

I'm sorry to tell you that window.open or <a href... does not work for this, only for files retrieved using either $http or ngResource. However, as your table needs data from some kind of server / data source, you could implement an exporting feature on the server side. Please be aware that such an exporting feature is not an easy-to-make function. What kind of backend are you using?

arjanvlek avatar Feb 25 '16 10:02 arjanvlek

We have a node.js and mongodb backend.

Hypocrite avatar Feb 25 '16 10:02 Hypocrite

There are various Excel export libraries available for the Node.JS environment, so I suggest taking a look at one of these. (https://www.npmjs.com/package/excel-export) To answer your original question: No, there is no improvement on the iOS / Safari situation.

arjanvlek avatar Feb 25 '16 10:02 arjanvlek

Thanks for the quick replies! We have to investigate the Node.JS solutions.

Hypocrite avatar Feb 25 '16 10:02 Hypocrite

@Hypocrite, the author's position: https://github.com/eligrey/FileSaver.js/issues/179#issuecomment-157862607

@arjanvlek, thank you for your contribution!

alferov avatar Feb 26 '16 00:02 alferov

So the author is asking about ideas where the problem might be? Has this worked in previous versions of Filesaver.js or has it been always broken?

Hypocrite avatar Feb 26 '16 06:02 Hypocrite

Any update with this?

I noticed there has been some development in the FileSaver.js GitHub: https://github.com/eligrey/FileSaver.js/issues/179 https://github.com/eligrey/FileSaver.js/pull/240

Hypocrite avatar Jun 20 '16 09:06 Hypocrite