1

I am having trouble exporting some data from one meteor application (meteor application 1) as a CSV, then uploading that CSV file to a separate meteor application (meteor application 2) . Specifically, while the file is exported from meteor application 1 with utf-8 encoding, I do not know how to “tell” meteor application 2 that the csv encoded in utf-8 format. As a result, the data, as received by meteor application 2 gets corrupted with utf-8 jargon like “%u2019” etc

I’m using the package clinical:csv from atmosphere.js, which is built on top of Papa Parse.

The relevant exporting lines of code in meteor application 1 are:

'click #exportMe':function(){
  var csvContent = CSV.unparse(Tasks.find().fetch());
  window.open('data:text/csv;charset=utf-8,' + escape(csvContent), '_self');
},

The relevant importing lines of code in meteor application 2 are:

Template.example.events({
  'change #hiddenUpload': function(event){
    var filesList = event.currentTarget.files;
    var file = filesList[0];
    Papa.parse(file, {
        header:true,
        complete: function(results) {
          var data = results.data
          Meteor.call('tasks.batch',data)
        }
      });
  },
})

I would guess that there would be a way of specifying in the importing code, that it’s encoded in utf-8, but have not been able to find anything in any relevant documentation.

Would be really grateful for any help.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Mark
  • 13
  • 1
  • 4

3 Answers3

1

In your code, try putting a encoding option like below:

Papa.parse(file, {
        header:true,
        encoding: "ISO-8859-1",
        complete: function(results) {
          var data = results.data
          Meteor.call('tasks.batch',data)
        }
      });
David Buck
  • 3,752
  • 35
  • 31
  • 35
0

Use the encoding option (alongside header and complete) of Papa.parse

http://papaparse.com/docs#config

As for the "%uxxxx" characters, they are not caused by the utf-8 charset encoding, but by the escape function that you apply.

ghybs
  • 47,565
  • 6
  • 74
  • 99
  • Thanks so much for the help, but I can't seem to get that to work. I've tried: encoding: "utf-8", encoding: "UTF-8", encoding: "charset=utf-8", encoding: utf-8, Any more ideas please? – Mark Feb 02 '18 at 05:54
  • You have escaped your string. That is where your strings come from. – ghybs Feb 02 '18 at 10:36
0

Try Using google sheets ,microsoft excel has a problem and also set UTF-8 encoding on papa parser.For me i changed from microsoft excel to google sheet and it worked.