I am using django-rest-framework as my backend and I want to upload an Image from the frontend(vuejs2) note: the backend works perfectly and I can upload the photo using django admin
1 Answer
I assume your backend accept multipart/form-data and using axios
<input type="file" @change="onFileChange" />
export default {
methods: {
onFileChange(e) {
const formData = new FormData();
formData.append("file", e.target.files[0]);
axios
.post("/upload", formData)
.then(() => {
console.log("SUCCESS");
})
.catch(() => {
console.log("FAILED");
});
},
},
}
1 Comment
Wassim Mriri
Thank you for your response sending a formdata made it work because I was sending the data in a form instead of a formdata