0

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
  • What have you tried so far? And what doesn't work? Commented Feb 6, 2022 at 0:11

1 Answer 1

1

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");
        });
    },
  },
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response sending a formdata made it work because I was sending the data in a form instead of a formdata

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.