Reputation: 175
I need to send file via axios POST request to a remote API with the following parameter : 'operation' => 'x' and 'files' => the file itself.
The file is a pdf file. I tried this:
let formData = new FormData();
formData.append('operation', 'x');
formData.append('files', this.file);
axios({
url: 'http://xxxxx',
method: 'POST',
data: formData,
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data'
}
}).then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
}
But I cannot get it work. I trieed also using set method on formData but it doesn't work aswell. Is there something I am making wrong? PS. I tried with POSTMan and it works so it is not an API problem. Thank you.
Upvotes: 0
Views: 5633
Reputation: 790
Maybe this help
axios.post(url, {params: {}}).then().catch()
Upvotes: 2