Frédéric
FileUpload: Button to change the image.
I try te remake a upload file with view field. If I understand well, to work I need to send the picture in ajax in the temp folder and store the name in an input with name data.${model attribute}. after I have te make the picture treatment by my own
4 replies
How come filename include the directory
you confuse me ^^' I install filament on two applications,the first one I let the default :
FileUpload::make('carrousel')
->image()
->getUploadedFileNameForStorageUsing(fn($get) => CarHelper::defineImageName($get))
->directory(fn($get) => 'images/cars/'. $get('plate'))
->imagePreviewHeight(160)
->columnSpanFull()
->multiple()
->appendFiles(false)
->reorderable()
it register: ["images/cars/TJ182MI/car-1-1.webp","images/cars/TJ182MI/car-1-2.webp","images/cars/TJ182MI/car-1-3.webp","images/cars/TJ182MI/car-1-4.webp"]
Well, maybe that's why it's the default 😉So I don't understand this ^^'
You'd need to update the DB data.With a big amount of datas I prefer juste change the method in my model who generate the path !
75 replies
How come filename include the directory
Thx to your help, juste a single question, if during the application's life I decide to change the structure file, how can I manage easily if the filepath is fully in the db ? with only the filename in the database, i juste need to change my config file, it's seem to be a good practice.
75 replies
How come filename include the directory
you speak abount this ?
$this->saveUploadedFileUsing(static function (BaseFileUpload $component, TemporaryUploadedFile $file): ?string {
try {
if (! $file->exists()) {
return null;
}
} catch (UnableToCheckFileExistence $exception) {
return null;
}
if (
$component->shouldMoveFiles() &&
($component->getDiskName() == (fn (): string => $this->disk)->call($file))
) {
$newPath = trim($component->getDirectory() . '/' . $component->getUploadedFileNameForStorage($file), '/');
$component->getDisk()->move((fn (): string => $this->path)->call($file), $newPath);
return $newPath;
}
$storeMethod = $component->getVisibility() === 'public' ? 'storePubliclyAs' : 'storeAs';
return $file->{$storeMethod}(
$component->getDirectory(),
$component->getUploadedFileNameForStorage($file),
$component->getDiskName(),
);
});
75 replies