FileReader to String

前端 未结 1 1187
说谎
说谎 2021-01-05 01:07

Consider the following code

function readSingleFile(evt) {
    //Retrieve the first (and only!) File from the FileList object
    var myFile = evt.target.file         


        
相关标签:
1条回答
  • 2021-01-05 01:10

    That's not how you get the result of a FileReader. Modify your code to this:

    function readSingleFile(evt) {
            //Retrieve the first (and only!) File from the FileList object
            var myFile = evt.target.files[0];
            var reader = new FileReader();
            reader.readAsText(myFile);
            reader.onload=function(){alert(reader.result)}
        }
    
    0 讨论(0)
提交回复
热议问题