Larasou
5 months ago
24
4
Vue

Upload a queue with data from one form at the same time.

Posted 5 months ago by Larasou

Hi people,

So I'm a little stuck with axios, I can not send data from a form with a file.

If I try to do that, I have a mistake.:

selectFile(e) {
    this.file = e.target.files[0];
},

submit() {
    const formData = new FormData();
    formData.append('file', this.file);


axios.post('/projets/store', {formData, this.form})
    .then(this.onSuccess)
    .catch(this.onFailure);
},

onSuccess(response) {
    console.log(response.data)
    //window.location = response.data.redirect;
},

onFailure(error) {
    this.form.errors.record(error.response.data.errors);
},

If I only send the formDara constant, it works.

axios.post('/projets/store', formData)
    .then(this.onSuccess)
    .catch(this.onFailure);
},

the same if I send only the this.form.

He would have a solution please?

Please sign in or create an account to participate in this conversation.