How to send a file to axios correctly?
File:
const onHandleFileRender = e => {
if(e.target.files[0] !== null) {
const file = e.target.files[0];
setFileData(file);
}
};
Request:
newFile = data => {
// data - my img
return axios.post(`${this._url}/api/v1/files`, data, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
UPD: My request:
newFile = data => {
const formData = new FormData();
formData.append("image", data);
return axios.post(`${this._url}/api/v1/files`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
};