4
I’m trying to upload an image using the library Axios, but she’s not getting into the back-end.
Image input
<input type="file" class="custom-file-input" id="file" name="file">
Note: My form already has the enctype="multipart/form-data"
Jquery code
var formData = new FormData();
var imagefile = document.querySelector('#file');
formData.append("image", imagefile.files[0]);
axios.post('http://localhost:3030/api/admin/employees', {
cpf,
formData
}, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(function (response) {
console.log(response);
});
Node.js returning data
return res.send(req.body);
Return of the API
config: {
url: "http://localhost:3030/api/admin/employees",
method: "post",
data: "{"cpf":"321.321.321-32","formData":{}}",
headers: {…}, transformRequest: Array(1), …
}
data: {}
headers: {content-length: "2", content-type: "application/json; charset=utf-8"}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 200
statusText: "OK"
I’ve tried many ways but nothing’s working.