Read the contents of a “file” object?

前端 未结 2 1126
温柔的废话
温柔的废话 2021-02-19 03:29

So I have a \"File\" object (retrieved by handling file drag and drop from desktop). I can send the files to the server with ajax, and then throw them back for javascript to han

2条回答
  •  悲&欢浪女
    2021-02-19 03:56

    Using the links from Martin Mally (thanks a lot!), I came up with this:

    var file = e.dataTransfer.files[0],
        read = new FileReader();
    
    read.readAsBinaryString(file);
    
    read.onloadend = function(){
        console.log(read.result);
    }
    

    Where read.result holds the contents of the file.

提交回复
热议问题