[Vuejs]-Success upload file via postman but fail on front-end (vue)

0👍

try this:

  1. First create the variable.

    var photo = ref();

  2. bind to input file tag

    <input
    id="photo"
    type="file"
    name="photo"
    hidden
    @change="previewImage"
    @input="photo= $event.target.files[0]"
    />

  3. This is the upload function

    const uploadImg = () => {

    var formData = new FormData();
    formData.append("photo", photo);

    (async () => {
    await axios
    .post(route("editImg"), formData, {
    headers: {
    Accept: "application/json",
    "X-Requested-With": "XMLHttpRequest",
    "Content-Type": "multipart/form-data",
    },
    credentials: "same-origin",
    })
    .then((response) => {
    console.log(response);

      .catch((e) => {
        console.log("err = ", e);
      });
    

    })();
    };

Leave a comment