matt_panton's avatar

Vue resource cannot upload file.

Hi, I've been stuck on this for longer than I'd link to admit and would really appreciate any help. I'm making a POST request through vue-resource and it works fine until I want to send a file along with the title. When I attach the file and dd($request->all()) in the controller, an empty array is shown, even though when I send just the title it shows up fine. Here is the code in the method that is creating the FormData object and submitting it:

let form = new FormData();
 form.append('video', document.getElementById('video').files[0]);
 form.append('title', this.title);

 this.$http.post('/upload', form).then(response => console.log(response.data));

I've done a console.log(form) and it shows that the FormData object does include both the file and the title.

Any help would be really great

0 likes
2 replies
BakerCo's avatar

Try form.append('name', file, 'filename');

rdelorier's avatar

I had to add the _method field to make it work since it's multipart

Please or to participate in this conversation.