I have a need to post a single image and also multiple images. The way I post data is quite easy
var optionAxios = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
};
axios
.post(
"https://example.com/users/update_profile",
{
currency: this.currency,
email: this.email,
country: this.country,
names: this.names,
language: this.language,
userid: this.$store.state.userid,
telephone: this.telephone,
},
optionAxios
)
.then((response) => {})
.catch(function (error) {
console.log(error);
});
I want to post a file and I was wondering if formData is the only available method I can attach single and multiple files in Axios.
The formData method
let formData = new FormData();
formData.append("file", this.file);
this.axios
.post("http://localhost:8000/api.php", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
})
.then(function (response) {
console.log(response.data);
})
.catch(function () {
console.log("FAILURE!!");
});
Would it be possible to attach a file or multiple files to post data without using formData?