2

I'm using Papaparse and I'm trying to parse a CSV file which is saved in a folder within www.

It works well with android and browser platform.

However, when it comes to iOS, it returns the error callback.

When I output the error, it returns undefined.

I also checked whether the file path for iOS is correct, and the file does exist.

I have already tried setting the file path as "folder/myfile.csv" but since it resulted in an error, I tried to get its full path using the file plugin.

Anyone else encountered the same problem and have a workaround?

This is my code.

var getOldData = function() {
    var dir = "folder/myfile.csv",
        file = null;

    file = (isiOS) ? cordova.file.applicationDirectory + "www/" + dir : dir;

    Papa.parse(file, {
        download: true,
        error: function(err, file) {
            console.log(">>>> PAPA PARSE ERROR");
            console.log(">>>>" + err); // this returns undefined
            console.log(">>>>" + file); // this returns undefined as well
        },
        complete: function(results) {
            console.log(">>>> PAPA RESULTS");
            console.log(results);
        },
        header: true,
        dynamicTyping: true
    });
};

Thanks in advance!

dariru
  • 501
  • 6
  • 16

1 Answers1

2

Same problem here.

I found this issue in pouchdb load on ios. It seems that

... for some reason, iOS is returning 0 as the status for the xhr request even when there is data loaded from file

So i changed in the papaparse _chunkLoaded function, this line

if (xhr.status < 200 || xhr.status >= 400)

by this one:

if (!((xhr.status >= 200 && xhr.status < 300) || (xhr.status==0 && xhr.responseText.length>0)))

And now it works.

I have added the same answer in the corresponding github issue. May be this patch will be included.

gontard
  • 28,720
  • 11
  • 94
  • 117
  • This is like magic, haha I had to go through parsing the file separately using the FileReader API, and then calling Papaparse, but your answer is much better. Thanks! I hope they include the patch soon. – dariru Jul 06 '16 at 08:45