2

I'm uploading the formData and somehow I'm getting a empty file on the headers using this

 var formData = new FormData(document.getElementById('creationForm'));
 console.log(file);
 formData.append("fileUpload", file);

It just doesn't work when i do the drag and drop. So how do I append the file to the actual input that is on the creationForm?

<input type="file" name="fileUpload" id="fileUpload" class="hide"/>
  • If I do `$('#fileUpload').val(file);` it give me Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. –  Mar 08 '18 at 13:11
  • Some Security Reason. Look for [more](https://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html) – Muhammet Can TONBUL Mar 08 '18 at 13:16
  • Possible duplicate of [How to set a value to a file input in HTML?](https://stackoverflow.com/questions/1696877/how-to-set-a-value-to-a-file-input-in-html) – Muhammet Can TONBUL Mar 08 '18 at 13:16
  • so how can i do this? console.log of the file has the file there and when I append it to the formData i get a file with size 0?? –  Mar 08 '18 at 13:17
  • This might help: https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean – Michael Nelles Mar 08 '18 at 13:27
  • I assume you can use the files property: **file.files[0]** – gaetanoM Mar 08 '18 at 13:37

1 Answers1

0

Don't understand the drag and drop, in IE can't drag n drop to a input type file, for example, but i think that this answer can help.

Gastón Corti
  • 51
  • 1
  • 6