1

I'm working in AngularJs the goal is to upload a file and save it as an a array using JS.

here is my HTML :

<input type="file" id = "uploadFile" name = "uploadFile" accept=".csv" required />
<button ng-click="processUploadedFile()"
        <div class="ml20 large-font">Process uploaded file</div>
</button>

Here is my function to process the uploaded file:

$scope.processUploadedFile = function() {
    var f = document.getElementById('uploadFile').files[0],
        r = new FileReader();

    r.onloadend = function(e) {
      var data = e.target.result;
    }

    r.readAsBinaryString(f);
}

It is showing the result is NULL.

And my CSV file would be like this:

Header1   Header2    Header3

value1     value2     value3
value1     value2     value3
value1     value2     value3
1
  • Note that the readAsBinaryString method was once removed from the File API specification, but re-introduced for backward compatibility. Its use is not recommended. Commented Nov 23, 2019 at 21:04

1 Answer 1

-1

Yes, you can. You just create a script that splits the data according with the relevant *.CSV delimiters, or get a third-party script that does that.

One such script is Papa Parse.

You can follow the example at: https://www.js-tutorials.com/javascript-tutorial/reading-csv-file-using-javascript-html5/

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.