1

Problem: When I tried the following code in Meteor.js, the file is downloaded by Chrome as download (1) without any file extension.

Is e.target.download = "data.csv" supposed to both trigger the download of the file and rename it to "data.csv"? The naming of the file does not seem to work when using e.target.download

client/views/results.js

Template.results.events({
    'click #downloadCsv': function (e) {

        var csv = json2csv(data, false, true)
        e.target.href = "data:text/csv;charset=utf-8," + escape(csv) 
        e.target.download = "data.csv";  

      }
  })

Code snippet taken from https://github.com/axwaxw/json2csv/

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • That used to work, but in newer versions of Chrome it doesn't any more, has something to do with the way they validate CSV data in the newer versions as far as I can understand. – adeneo Jun 08 '14 at 19:44
  • @adeneo Any workaround for this? I tried using `data.xls` instead of `data.csv` and it's still downloading as `download (1)`. Maybe we can save the file to disk before triggering the download, but how can this be done? – Nyxynyx Jun 08 '14 at 19:46
  • I really don't know, I have several [answers](http://stackoverflow.com/questions/17836273/export-javascript-data-to-csv-file-without-server-interaction/17836529#17836529) that I've posted using the download attribute, and they all stopped working in Chrome a few weeks back. I tested a lot with CSV data back then, but couldn't seem to get the filename to work, yet it works on images etc. It's got something to do with data like CSV, XML etc. being validated when the `:data` prefix is used, remove `:data` and the filename is set, but the file is empty, so it's basically a bug in newer versions. – adeneo Jun 08 '14 at 19:57

0 Answers0