DEV Community

Kelvin Chidothi
Kelvin Chidothi

Posted on

5 3

Uploading Multiple Files in Vue.js using a Laravel API

Image description

Recently l wanted to upload documents from Vue.js to a Laravel backend. All API's were set up and were working in Postman. Doing in vue.js was a bit of a problem. l was using Vuetify for the styling so l used a v-file-input set to multiple using the predefined prop.

On upload, l was using Axios. Basic stuff. To attach documents l created an instance of FormData() and appended the documents formData.append('images[]', this.images).

In my controller in Laravel, l was looping over the array of images and storing them:

foreach($request->file('images') as $image){
  $image->store('docs');
}
Enter fullscreen mode Exit fullscreen mode

This implementation failed and l did alot of modifications and turns out l had to loop over the documents also in Vue.js like this:

this.images.foreach((image, index) => { formData.append('images[]', image) });
Enter fullscreen mode Exit fullscreen mode

This finally worked and l hope it works for you too!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs