Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  175] [ 5]  / answers: 1 / hits: 10286  / 10 Years ago, wed, june 11, 2014, 12:00:00

I am working on a drag and drop file upload field.



I am able to return a FileList object containing the file that has been specified by the user. I have a hidden file input field which I then want to add the file object to so I can then send the form data via AJAX.



The problem I am having is that I can't seem to copy the file object to the file input field. Here is how I am attempting it:



var files = evt.dataTransfer.files; // FileList object.
var fileUploadElem = document.getElementById(fileUploadId);

// trying to copy the first file of files into the file upload field
fileUploadElem.files[0] = files[0];

// this statement returns '0' instead of '1'
console.log('fileUploadElem length: '+fileUploadElem.files.length);


Appreciate any advice or pointers.


More From » file-upload

 Answers
4

The reason it didn't work for me was because one of the JavaScript properties isn't supported in Chrome hence it worked on my colleague's machine who was working within the Firefox browser but not for me.


[#44646] Tuesday, June 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
abagail

Total Points: 528
Total Questions: 109
Total Answers: 101

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
;