Send a drag and drop file to enter file type

I have a form builder and I want to add the ability to drag and drop files.

Where am I stuck with is that all the resources that I encounter load the image via xhr when deleting. I want the image to be saved until the form is submitted.

Ideally, the event.dataTransfer.files[0] object will be passed to the <input type="file" ...value="[dropped-file]"> element.

Currently, I cannot do this. Do they use compatible data types?

+4
source share
1 answer

You can simply create and submit the form after the redirect event has occurred, and the user will click the conf button. This is its essence: (not verified).

 function uploadFile(file) { var form = new FormData(), xhr = new XMLHttpRequest(); form.append('media', file); xhr.open('POST', '/myurl/'); xhr.onprogress = function(e) { showProgress(); } xhr.onload = function(e) { showSuccessConf(); } xhr.send(form); } uploadFile(event.dataTransfer.files[0]); 
+3
source

Source: https://habr.com/ru/post/1493509/


All Articles