Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read a Drag and Dropped file

I tried uploading files with the dataTransfer.files but what is the method or property that should be used for reading a single file?

like image 419
user3428217 Avatar asked Mar 26 '14 11:03

user3428217


People also ask

What is drag and drop file?

Drag-and-drop editing describes any editing performed by dragging an image, text, or object from one place to another. For example, to move text from one place to another in a document, you could select the text and then click-and-drag that text to another location.

How do I enable drag and drop files?

Use the Esc Key and Left Click Locate the file or folder you wish to move by left-clicking on it on your desktop. Hit the “Escape” key on your keyboard once. Release the left-click on your mouse. Drag and drop functionality should now work as normal.

What is a drop file?

Noun. dropfile (plural dropfiles) (computing, dated) A file used by a bulletin board system (BBS) to pass information about the BBS itself and the current user to an external door.


1 Answers

FileReader.readAsArrayBuffer()
Starts reading the contents of the specified Blob, once finished, the result attribute contains an ArrayBuffer representing the file's data.
FileReader.readAsBinaryString()
Starts reading the contents of the specified Blob, once finished, the result attribute contains the raw binary data from the file as a string.
FileReader.readAsDataURL()
Starts reading the contents of the specified Blob, once finished, the result attribute contains a data: URL representing the file's data.
FileReader.readAsText()
Starts reading the contents of the specified Blob, once finished, the result attribute contains the contents of the file as a text string.
following demo can be helpful for you
Demo

var file = e.dataTransfer.files[0],
      reader = new FileReader();
  reader.onload = function (event) {
    console.log(event.target.result);
    //holder.style.background = 'url(' + event.target.result + ') no-repeat center';

  };
  console.log(file);
  reader.readAsDataURL(file);
like image 67
Suraj Avatar answered Sep 22 '22 15:09

Suraj