preserveFilenames() not working with SpatieMediaLibraryFileUpload

Hi, I'm using the SpatieMediaLibraryFileUpload in a Form Builder. The docs say: "You may use the field in the same way as the original file upload field", however I can't get preserveFilenames() to work. The uploaded files are always renamed - the instruction seems to get ignored completely. Is there anything I'm missing?
9 Replies
toeknee
toeknee3w ago
Try placing it at the end of the field definition
czehnter
czehnterOP3w ago
No luck, it was already at the end.
Dennis Koch
Dennis Koch3w ago
Not sure whether that method works on with SpatieFileUpload since Spatie handles the upload and storage and not Filament
czehnter
czehnterOP3w ago
I might be wrong, but I don't think the Spatie Media Library is renaming files by default. It seems like it is the standard filament behaviour and preserveFilenames() is just not working.
toeknee
toeknee2w ago
Question.. is this is the download or the storage? I am using this perfectly well:
SpatieMediaLibraryFileUpload::make('document')
->hiddenLabel()
->disk('s3_data')
->collection('documents')
->downloadable()
->openable()
->visibility('private')
->acceptedFileTypes(['application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
->preserveFilenames(),
SpatieMediaLibraryFileUpload::make('document')
->hiddenLabel()
->disk('s3_data')
->collection('documents')
->downloadable()
->openable()
->visibility('private')
->acceptedFileTypes(['application/vnd.openxmlformats-officedocument.wordprocessingml.document'])
->preserveFilenames(),
czehnter
czehnterOP2w ago
I was referring to the filename in storage, I'm not using ->downloadable(). So with this config, the files won't be renamed on the storage in your environment?
toeknee
toeknee2w ago
Where are you storing it? That stores correctly in storage for me.
czehnter
czehnterOP2w ago
I tested different disks, but the result is always the same. I also tried using the documented method for custom names and then just returning the original name in it, but this also doesn't change anything:
->getUploadedFileNameForStorageUsing(
fn(TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName()),
)
->getUploadedFileNameForStorageUsing(
fn(TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName()),
)
czehnter
czehnterOP2w ago
I also tried using the default FileUpload field instead and it doesn't work there either. I also found someone else with the same problem, so at least I'm not alone 😅 https://github.com/filamentphp/filament/issues/12368
GitHub
Error when calling preserveFilenames function in Class Forms\Compon...
Package filament/filament Package Version 3.1.31 Laravel Version 10.48.8 Livewire Version No response PHP Version 8.1 Problem description Error when calling preserveFilenames function in Class Form...

Did you find this page helpful?