How to upload and read CSV files in React.js?

后端 未结 3 1319
终归单人心
终归单人心 2020-12-23 12:16

I would like the user to upload a .csv file, and then have the browser be able to parse the data from that file. I am using ReactJS. How would this work? Thanks.

3条回答
  •  一整个雨季
    2020-12-23 12:24

    Figured it out. A combination of react-file-reader and HTML5's FileReader (see this page).

    Placed the react-file-reader bit inside of render:

    
        
    
    

    And then this above.

    handleFiles = files => {
        var reader = new FileReader();
        reader.onload = function(e) {
            // Use reader.result
            alert(reader.result)
        }
        reader.readAsText(files[0]);
    }
    

提交回复
热议问题