I have created an input that can receive a file. Once the submit button is clicked, I set up a form Data, try to append the file to it, and then launch an axios post request to a server.
Sadly, I don't know how to pass the file to formData:
button.onclick = function(){ let formData = new FormData(); formData.append('myFile', e.dataTransfer.getData("files")); axios.post("/api/upload", formData) .then(response =>{ console.log(response.data)}) .catch(err=> { console.log("error") }) } What is the correction to add to e.dataTransfer.getData("files")? The input file can be an image, a pdf, etc. The input looks like that:
<input type="file" multiple/> Thanks.
e, which should be obvious from the error message you get. And missing)before.catch, plus all kinds of open braces.e.dataTransferseems to only exist for DragEvents, not ClickEvents. You need to grab the selected file from the input:document.querySelector('input').files[0](assuming it's the only<input>on the page)