Read the contents of a “file” object?

前端 未结 2 1127
温柔的废话
温柔的废话 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:50

    I think it's possible; check these two articles:

    1. https://developer.mozilla.org/en/Using_files_from_web_applications
    2. http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/

    They both manipulates with "dropped" file via JS/HTML before uploading to server. (e.g. picture resizing etc.) I hope it helps.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题