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
FileUploadcomponent 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
TemporaryUploadedFileinstead 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
FileUploador 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.