Sopamo / laravel-filepond

Laravel backend module for filepond uploads
MIT License
203 stars 56 forks source link

Cannot use object of type Illuminate\Http\UploadedFile as array in file #22

Closed LTroya closed 4 years ago

LTroya commented 4 years ago

I'm getting this error using the 0.2.0 version when I upload a file. This is the exact error:

Symfony\Component\Debug\Exception\FatalThrowableError: Cannot use object of type Illuminate\Http\UploadedFile as array in file /var/www/kapa99/vendor/sopamo/laravel-filepond/src/Http/Controllers/FilepondController.php on line 32

Looking into the source code, it happens because is using [0] on this line

$request->file('file')[0]

If I remove [0], it works as expected. On the chrome developer tool network tab it's always sending one request by file

image

Filepond client: https://github.com/pqina/vue-filepond Laravel version: 6.2

pocketarc commented 4 years ago

This seems related to Laravel 6.x. The easy way to resolve it in a backward-compatible manner is:

$file = $request->file('file');
$file = is_array($file) ? $file[0] : $file;

It might be worth investigating this in a bit more depth, though.

Sopamo commented 4 years ago

This has been fixed in v0.4.