I feel like I must be missing something very simple but I've lost track of everything I've tried over the past 3 days... I'm using medialibrary-pro for the temporary upload functionality on attachment to upload direct to S3.
First, my configs:
.env
MEDIA_DISK="s3-media"
config/filesystems.php has my s3 disk defined:
's3-media' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
'endpoint' => env('AWS_ENDPOINT'),
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
'root' => 'media-manager'
],
media-library.php is stock generated by artisan, the disk name you can see above is set in my .env file:
return [
'temporary_file_upload' => [
'rules' => 'file|mimes:png,jpg,jpeg,gif|max:2048',
'disk' => 's3-media',
],
];
My form blade view contains:
<x-media-library-attachment name="media" rules="mimes:png,jpg,jpeg,gif|max:2048"/>
My controller has:
$media
->addFromMediaLibraryRequest( $request->get('media') )
->toMediaCollection('user-media', 's3-media');
And now what happens...
Now I click the submit on my form. and get the following exception:
fopen(/srv/users/username/apps/app-name/storage/media-library/temp/HSutOfGcDuysxkxNRJwMYo42L5RaclTU//file_name.jpg): Failed to open stream: No such file or directory
Any suggestions and help is greatly appreciated!
Seems like running save() on your model causes all sorts of problems. I went back to the example code at https://github.com/spatie/laravel-medialibrary-pro-app and rewrote my queries to use the create method rather than an insert. As soon as I took the $model->save() out of the equation everything worked as expected. I ended up creating a local media disk for the temp uploads and then when I process the upload I send it over to my s3-media disk.