[Vuejs]-How to upload an image from vue js to django rest framework?

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");
        });
    },
  },
}

Leave a comment