Upload a CSV file from Web IDE and parse

Posted on
  • I'm making an app to load some sets of GPS coordinates (latitude and longitude) to the storage area by uploading from the Web IDE, using 4 disc icon, and then read those coordinates from the app and calculate distances.
    Anyway, I made a CSV file in the Notepad++ with comma separated and saved with Unix LF option. Then I tried to read the data from the Web IDE console using following code, but didn't work.

    var f = require("Storage").open("coordinate.csv"­,"r");
    var l = f.readLine();
    while (l!==undefined) {
      console.log(+parseFloat(l.split(',')[0])­.toFixed(6)); 
      console.log(+parseFloat(l.split(',')[1])­.toFixed(6));
      l = f.readLine();
    }
    

    I found an app called 'gpspoilog' from this tutorial page, and used it outdoor to create a CSV file by the app and used the suggested read code from the tutorial and it worked fine.

    From the storage file list (by clicking the 4-disc icon), I noticed the generated log file has a name 'gpspoilog.csv (StorageFile).csv (StorageFile)'

    So, I guess there are some differences between the data file generated by an app and manually uploaded one.

    I want to upload those GPS data manually and read them in my app. Is there any way to do it?

    Thanks.

  • Yes, read this

  • @MaBe, thank you for your reply, but as I described, using the upload button from the 4 discs icon, that's exactly what I did.

  • you can give it a name, please read the hole conversation it also includes a possibility for uploading without the WebIDE.

  • @MaBe, I have already read the entire post and found you wanted to upload a module. I don't quite understand what you meant by 'you can give it a name', but when you upload a file, it asks what filename you want to upload your file to the storage area. Is this what you meant? If so, yes, I know.
    Thanks anyway.

  • Hi, the issue is the difference between StorageFile (made/read with .open) which is a variable length file, and files that are made with .write (and read with .read) and are fixed length. When you upload with the IDE you can only upload normal files, not StorageFile

    You might be able to do:

    var f = require("Storage").open("coordinate.csv"­,"r");
    f.write(require("Storage").read("coordin­ate.csv"));
    require("Storage").erase("coordinate.csv­");
    

    on the Bangle to convert the non-storagefile to a storagefile though

  • @Gordon, thank you so much for your explanation in detail. That’s exactly what I wanted to know.
    Cheers!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Upload a CSV file from Web IDE and parse

Posted by Avatar for JeonLab @JeonLab

Actions