jeudi 8 juin 2017

Store multiple files from API in Laravel

I have an API with Angular 2 and I send multiple files with FormData to Laravel backend.

This is a working example for one file:

$file = $request->file('file');
$extension = $file->getClientOriginalExtension();
$entry->filename = $file->getFilename().'.'.$extension;
Storage::disk('documents')->put($file->getFilename().'.'.$extension,  File::get($file));

Where $entry is a new model where I store some meta data for the file.

However, I cannot make it work with multiple files at the same time. Here is the formdata I send

Content-Disposition: form-data; name="files"

[object File],[object File],[object File]

So, if I try with:

$file = $request->file('files');

I have NULL. Is there an alternative way or I should do a "hack" to send multiple form data entries with all the files and get those in Laravel dynamically?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire