[Vuejs]-Multiple image upload only append the last data in Axios post but not each of the data

1πŸ‘

βœ…

I don’t understand the problem but as I can see you use the same formData object for every call. I think you should initialize FormData in the loop, it can cause strange cases.

By the way, I think you can submit multiple files in one axios call too:

postitem() {
      let formData = new FormData();
      for (var i = 0; i < this.file.length; i++) {
        var obj = this.file[i];
        formData.append("filename[]", obj);
      }
      axios.post(`url/test/postimages`, formData, {
          headers: { Authorization: `Bearer ${token()}`,
    'Content-Type': 'multipart/form-data' },
        }).then((response) => {
          if (response.status === "error") {
            alert("error");
            this.loading = false;
          } else {
            alert("success");
          }
        });
    },

Leave a comment