F
F
fiter2017-06-02 20:50:13
JavaScript
fiter, 2017-06-02 20:50:13

How to add a file to a post request in axios?

Vue 2, axios, send form post request: Object with form:
axios.post( '/addTrack', this.form.data )

form: {

                    data: {

                        title : '',
                        style : '',
                        authors: [
                            {
                                id: '',
                                rightholder: 1,
                                percent: ''
                            }
                        ],
                        composers: [
                            {
                                id: '',
                                rightholder: 1,
                                percent: ''
                            }
                        ],
                        file: '',
                        right_area: 1,
                    },

                    errors: {

                    }

                }

How to attach a file to this request?
Tried like this, but didn't work:
this.form.data.file = e.target.files[0];

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
fiter, 2017-06-05
@fiter

The decision was made to do this:

var formData = new FormData( document.getElementById('myForm') );

L
lem_prod, 2017-06-02
@lem_prod

use FormData for request body
https://developer.mozilla.org/ru/docs/Web/API/FormData

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question