F
Filamentβ€’16mo ago
cwbmuller

Store the full file upload URL not just the filesystem extension

I am trying to use the file upload field to store an image url to a model image column. I want the full asset url to be stored to the database, not just the extension of the filesytem path. The file is being uploaded fine but when saving to the database only the extension is being saved, not full path. Am I missing something or do I need to hydrate the column everytime?
6 Replies
cwbmuller
cwbmullerOPβ€’16mo ago
For example the form is storing sEyBoG7HX4s5iqW2W4EXofWTx35cko-metaU2NyZWVuc2hvdCAyMDIzLTA4LTExIGF0IDE0LjU5LjE5LnBuZw==-.png But I want the full url stored eg: https://{aws_url}sEyBoG7HX4s5iqW2W4EXofWTx35cko-metaU2NyZWVuc2hvdCAyMDIzLTA4LTExIGF0IDE0LjU5LjE5LnBuZw==-.png I can get the full url stored like this, but it seems super hacky
->formatStateUsing(fn (string $state): array =>[basename($state)])
->dehydrateStateUsing(fn (array $state): string => Storage::disk('general')->url('').array_values($state)[0])
->formatStateUsing(fn (string $state): array =>[basename($state)])
->dehydrateStateUsing(fn (array $state): string => Storage::disk('general')->url('').array_values($state)[0])
Dennis Koch
Dennis Kochβ€’16mo ago
I think there is a ->storeFilenameUsing() method or similar on the FileUpload?
cwbmuller
cwbmullerOPβ€’16mo ago
As far as I can tell that's specific to the filename customization and not storing full path rather than just filename @Dennis Koch unless that's not documented πŸ€”
toeknee
toekneeβ€’16mo ago
Q why are you storing the full url? The reason the filename is stored is because you are using a disk so that disk should relate the to path that is being stored i.e. filename.
Dennis Koch
Dennis Kochβ€’16mo ago
Ah right. I remember someone having the same issue. I think your approach is valid then.
cwbmuller
cwbmullerOPβ€’16mo ago
@toeknee_iom Storing the full path URL so that the asset can be accessed in various places without having to remember which filesystem it was uploaded to? Ie: the record column includes the asset url instead of an abstracted filename of a specific filesystem. Not sure if i'm explaining myself well πŸ˜… Thanks @Dennis Koch it does solve my problem πŸ‘
Want results from more Discord servers?
Add your server