I use a custom file namer that changes the name of the uploaded file:
class FileNamer extends \Spatie\MediaLibrary\Support\FileNamer\FileNamer
{
public function originalFileName(string $fileName): string
{
return Auth::user()->id.'-'.pathinfo($fileName, PATHINFO_FILENAME);
}
public function conversionFileName(string $fileName, Conversion $conversion): string
{
return pathinfo($fileName, PATHINFO_FILENAME).'-'.$conversion->getName();
}
public function responsiveFileName(string $fileName): string
{
return pathinfo($fileName, PATHINFO_FILENAME);
}
}
It works just fine when I edit an existing resource. The problem arises when I create a resource. When I upload a new file, before saving the resource in Nova, the file gets uploaded, but when I check the preview, I can see the original name. However, when I save the resource, the file name changes and then everything works just fine.
I use a custom file namer that changes the name of the uploaded file:
It works just fine when I edit an existing resource. The problem arises when I create a resource. When I upload a new file, before saving the resource in Nova, the file gets uploaded, but when I check the preview, I can see the original name. However, when I save the resource, the file name changes and then everything works just fine.