Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kylef-fotf's avatar

array_keys(): Argument #1 ($array) must be of type array, Livewire\Features\SupportFileUploads\TemporaryUploadedFile given

I'm using Filament 4 with Spatie-Media-Library 3.3

In a model's edit/create page, if I upload a file (of any kind) using SpatieMediaLibraryFileUpload it will appear in storage/app/private/livewire-tmp

When I submit the form it throws this error:

array_keys(): Argument #1 ($array) must be of type array, Livewire\Features\SupportFileUploads\TemporaryUploadedFile given

and the file is never moved out of /livewire-tmp

If I use Filament's standard FileUpload class it will work and the file is properly saved.

Is there anything that can be done about this or is the Spatie-Media-Library just not ready for Filament 4? I can't find a place to report this issue on It's github page.

0 likes
2 replies
LaryAI's avatar

The error:

array_keys(): Argument #1 ($array) must be of type array, Livewire\Features\SupportFileUploads\TemporaryUploadedFile given

means that somewhere in your code (or in a package), a function expects an array but is receiving a TemporaryUploadedFile object instead.

Why This Happens

  • Filament's FileUpload component expects a file upload and handles it internally.
  • SpatieMediaLibraryFileUpload (from the Filament Spatie Media Library plugin) expects an array of files (to support multiple uploads), even if you only upload one file.
  • If you bind the property as a single file (not an array), the plugin receives a TemporaryUploadedFile instead of an array, causing this error.

Solution

Ensure your Livewire property is an array, even for single file uploads.

1. In your Filament form:

If you are using the SpatieMediaLibraryFileUpload field, make sure you set multiple() if you want multiple files, or handle the single file as an array.

use Filament\Forms\Components\SpatieMediaLibraryFileUpload;

SpatieMediaLibraryFileUpload::make('media')
    ->collection('your-collection-name')
    // ->multiple() // Uncomment if you want multiple files

2. In your Livewire component:

Make sure the property you bind to is an array:

public array $media = [];

If you want to allow only a single file, you can still use an array and just take the first item when saving.

3. Saving the file:

When saving, you can do something like:

if (!empty($this->media)) {
    $model->addMedia($this->media[0]->getRealPath())
        ->toMediaCollection('your-collection-name');
}

4. If you want to use a single file (not an array):

You can use Filament's standard FileUpload component instead, which works with a single file:

use Filament\Forms\Components\FileUpload;

FileUpload::make('file')
    ->disk('your-disk')
    ->directory('your-directory')

Summary

  • SpatieMediaLibraryFileUpload expects an array, so your property should be an array.
  • If you want single file upload, use Filament's FileUpload or always treat the property as an array and use the first element.

References

If you follow these steps, the error should be resolved and files will be moved out of /livewire-tmp as expected.

kylef-fotf's avatar

OK adding ->multiple() seems to have worked. I don't actually want multiple files in this case, but at least I can move forward and hopefully this will be fixed in the near future.

SpatieMediaLibraryFileUpload::make('media')->multiple()

Please or to participate in this conversation.