When I curl something, it works fine:
curl -L -i -H 'x-device-id: abc' -F "url=http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" http://example.com/upload
How do I get this to work right with axios? I'm using react if that matters:
uploadURL (url) {
return axios.post({
url: 'http://example.com/upload',
data: {
url: url
},
headers: {
'x-device-id': 'stuff',
'Content-Type': 'multipart/form-data'
}
})
.then((response) => response.data)
}
This doesn't work for some reason.
If you are sending alphanumeric data try changing
to
If you are sending non-alphanumeric data try to remove 'Content-Type' at all.
If it still does not work, consider trying request-promise (at least to test whether it is really axios problem or not)
ok. I tried the above two ways but it didnt work for me. After trial and error i came to know that actually the file was not getting saved in 'this.state.file' variable.
here fileUpload is a different js file which accepts two params like this
}
don't forget to bind method in the constructor. Let me know if you need more help in this.
Here's how I do file upload in react using axios
Source