This post its old but i solve with customPathDirectory, here the official doc. https: //spatie.be/docs/laravel-medialibrary/v10/advanced-usage/using-a-custom-directory-structure, in my case put this in my controller
$model->syncFromMediaLibraryRequest($request->file)
->addCustomHeaders([
'path' => 'root',
'preview' => 'anotherRoot or root'
])
->toMediaCollection('collection', 's3');
then in the customPathDirectory file i make this
public function getPath(Media $media): string
{
return $media->custom_properties['custom_headers']['path'];
}
and finally add you customPathDirectory file in the config media-library
'path_generator' => \App\Services\MediaLibrary\CustomPathDirectory::class,
now u can send file to any directory as you want.
NOTE: the url have one space between https: and // just remove and go