ng-csv icon indicating copy to clipboard operation
ng-csv copied to clipboard

filename attr is not woking in Safari

Open jeonghwan-kim opened this issue 10 years ago • 39 comments

Thank you for this code (ng-csv). I used it in my project.

However, in Safari, csv file is not download. It is printed in Safari browser's new tab. Aslo in Chrome browser filename attr is not working.

(Firefox is ok)

jeonghwan-kim avatar May 27 '14 06:05 jeonghwan-kim

Hi, Thanks for the report, Apparently Google pushed a bug in the latest version of Chrome. https://code.google.com/p/chromium/issues/detail?id=376197

I hope they will solve this soon enough, I'll check up on this in the next couple of days and if I won't see any progress I will try to find a workaround.

On Tue, May 27, 2014 at 9:58 AM, jeonghwan [email protected] wrote:

Thank you for this code (ng-csv). I used it in my project.

However, in Safari, csv file is not download. It is printed in Safari browser's new tab. Aslo in Chrome browser filename attr is not working.

(Firefox is ok)

— Reply to this email directly or view it on GitHubhttps://github.com/asafdav/ng-csv/issues/29 .

asafdav avatar May 27 '14 07:05 asafdav

Thank you for comment. :D

jeonghwan-kim avatar May 28 '14 02:05 jeonghwan-kim

The Chromium team merged the issue into this one https://code.google.com/p/chromium/issues/detail?id=373182

It should be fixed in a week or two. let's cross our fingers.

asafdav avatar Jun 01 '14 21:06 asafdav

I expect.

jeonghwan-kim avatar Jun 02 '14 00:06 jeonghwan-kim

Same issue. Hoping for a resolution.

tinybigideas avatar Jun 17 '14 15:06 tinybigideas

According to issue above, they solved it today, so we should expect a fix soon.

asafdav avatar Jun 17 '14 15:06 asafdav

I'm using chrome Version 35.0.1916.153 latest. When I click on export, it always choose "download.csv" as the filename even if I have the filename="export.csv" attribute set.

Also, I have the same issue as mentioned above where safari opens the CSV in a new tab.

amit777 avatar Jun 25 '14 23:06 amit777

I am facing the same issue with Chrome and Safari. Do we have any work around at this moment?

adityasabnis avatar Jul 09 '14 04:07 adityasabnis

Hi,

I don't have a good solution for Safari at the moment, as currently they ignore the html5 download attribute. We can try to find a good flash polyfill that will allow us to bypass that, Downloadify seems like a good option. If any of you have the time for it, I'll be more than happy to accept a pull request :)

As I mentioned above, The chrome team already solved the issue and the next version is just around the corner, If you use Chrome beta or Canary you can already see the it's solved. I hope it's a matter of days.

On Wed, Jul 9, 2014 at 7:54 AM, Aditya Sabnis [email protected] wrote:

I am facing the same issue with Chrome and Safari. Do we have any work around at this moment?

— Reply to this email directly or view it on GitHub https://github.com/asafdav/ng-csv/issues/29#issuecomment-48429965.

asafdav avatar Jul 09 '14 08:07 asafdav

hi, for a rapid solution of chrome problem, you can modify ng-csv.js else in line 211 for that

    else {
        var blob = new Blob([scope.csv],{ 
              type: 'text/csv' 
            });
        var csvUrl = URL.createObjectURL(blob);

        var downloadLink = angular.element('<a></a>');
        downloadLink.attr('href',csvUrl);
        downloadLink.attr('download',scope.getFilename());

        $document.find('body').append(downloadLink);
        $timeout(function() {
          downloadLink[0].click();
          downloadLink.remove();
        }, null);
      }

jmtt89 avatar Jul 17 '14 14:07 jmtt89

UPDATE: The latest version of chrome works as expected

asafdav avatar Aug 19 '14 21:08 asafdav

Thanks I will check it.

jeonghwan-kim avatar Aug 22 '14 02:08 jeonghwan-kim

Any updates about this? On safari i will get printed output, not a downloaded file..

Hesesses avatar Sep 08 '15 20:09 Hesesses

Same here, safari doesn't download the file. Any idea how to work around this issue?

mwager avatar Sep 11 '15 14:09 mwager

how it's going?

alexey-shaposhnikov avatar Dec 19 '15 20:12 alexey-shaposhnikov

This is because Safari doesn't allow downloading of blob urls. So FileSaver.js using base64data in case of Safari browser. How about using this code on Safari in our project?

if (isSafari()) {
    downloadContainer = angular.element('<div data-tap-disabled="true"><a></a></div>');
    downloadLink = angular.element(downloadContainer.children()[0]);

    // Safari doesn't allow downloading of blob urls
    var reader = new FileReader();
    reader.readAsDataURL(blob);
    reader.onloadend = function() {
        var base64data = reader.result;
            downloadLink.attr('href', 'data:attachment/file' + base64data.slice(base64data.search(/[,;]/)));
        };

        $document.find('body').append(downloadContainer);
        $timeout(function () {
            downloadLink[0].click();
            downloadLink.remove();
        }, null);
}        

jeonghwan-kim avatar Dec 27 '15 09:12 jeonghwan-kim

Has there been any progress on this issue?

ghost avatar Feb 22 '16 23:02 ghost

So I've been doing some research into this. It looks like Safari doesn't support the download attribute used in the dynamically created element in the directive's link function. From what I've been able to find, other developers have either directed their users through non-intuitive right-click then "save page as" or create a content stream that still results in losing the filename. I'll keep looking into this and if I find a work around or something that looks like it fits into ng-csv's without a lot of bloat I'll let yall know / make a pull request.

ghost avatar Feb 23 '16 19:02 ghost

I'm afraid I've had something higher priority come up but if I have a chance I'll get back to this.

ghost avatar Feb 24 '16 18:02 ghost

@asafdav - seems that Chrome 48.0.2564.116m on windows10 still doesn't have extname on the file.

id0Sch avatar Mar 01 '16 09:03 id0Sch

It's working like a charm on chrome. However, in Safari, csv file is not download yet. I'll try find a solution for it and make a PR guys. BTW... great work on this directive! :clap:

diego-oliveira avatar Apr 12 '16 17:04 diego-oliveira

@jeonghwan-kim I tried your code but unfortunately it didn't worked. Did you find a solution for it?

diego-oliveira avatar Apr 12 '16 17:04 diego-oliveira

  • one same problem in safari. Thanks @diego-oliveira, let us know if you find anything. ;-)

patioheaven avatar Apr 14 '16 03:04 patioheaven

@diego-oliveira : @jeonghwan-kim 's solution works fine when taken as a whole.

@asafdav If there's something wrong with the above (besides that it's not a pull request) or with @karrde00 's pull request, please comment on them - I'd be happy to help clean up, etc., if needed.

jnelson avatar Apr 21 '16 12:04 jnelson

@jnelson I'll give it a shoot again and see if it was some mistake from my side. Thanks.

diego-oliveira avatar Apr 21 '16 13:04 diego-oliveira

@diego-oliveira If you prefer the iframe approach, we have an up-to-date merge of @karrde00's pull request at https://github.com/xlhybridsOSS/ng-csv/tree/github_karrde00-master - initial testing against IE11 and Safari 9.1 for our immediate problem has been successful.

jnelson avatar Apr 21 '16 16:04 jnelson

Thanks guys for working on this! We just ran into an issue where a client tried to download our data in CSV on Safari and it did not work :(

leongaban avatar Apr 21 '16 22:04 leongaban

Has anyone managed to get either of the above solutions working on Safari for iPad / iPhone? Nothing happens when I click my save button using @jeonghwan-kim 's solution and I get an "unable to read file" error using @karrde00 's solution.

I also cannot download using the Android built-in browser, using any solution. It works in Chrome for Android though. Haven't seen anyone else mention this problem...

d0dge avatar Jun 04 '16 05:06 d0dge

+1

roccomuso avatar Oct 28 '16 12:10 roccomuso

+1

Lasto13 avatar Dec 05 '16 09:12 Lasto13

+1

farhanlatheef avatar Dec 07 '16 06:12 farhanlatheef

+1

lucaswhitman avatar Jan 11 '17 19:01 lucaswhitman

+1

ghilton000 avatar Feb 06 '17 16:02 ghilton000

+1

ryankidd avatar Mar 21 '17 23:03 ryankidd

downloadLink.attr('target', '_blank'); line prevent safari from downloading file. With this line it opens file in new tab while without it safari downloading file as expected.

Novarg avatar Apr 06 '17 16:04 Novarg

+1, any news?

henrique2601 avatar Jul 24 '17 14:07 henrique2601

@Novarg I tried commenting on that line that you mention and it works in Safari and Chrome, you should do a pull request with that change

Fercho191 avatar Jul 28 '17 16:07 Fercho191

+1

jokingzhang avatar Sep 05 '17 08:09 jokingzhang

+1

imcarvalho avatar Sep 26 '17 09:09 imcarvalho