F
Filament4mo ago
Cushty

Spatie media digital ocean spaces, folders

Hi I have got DO spaces working well with filament, the only issues is its only uploading to random folders with numbers, i set a directory but its not working, hope you can help, thanks
SpatieMediaLibraryFileUpload::make('avatar')
->directory('images/' . config('filesystems.disks.do.directory_env'))
->collection('avatars')
->label('Avatar')
->avatar()
->required()
->imageEditor()
->disk('do'),
SpatieMediaLibraryFileUpload::make('avatar')
->directory('images/' . config('filesystems.disks.do.directory_env'))
->collection('avatars')
->label('Avatar')
->avatar()
->required()
->imageEditor()
->disk('do'),
'do' => [
'driver' => 's3',
'key' => env('DO_ACCESS_KEY_ID'),
'secret' => env('DO_SECRET_ACCESS_KEY'),
'region' => env('DO_DEFAULT_REGION'),
'bucket' => env('DO_BUCKET'),
'url' => env('DO_URL'),
'endpoint' => env('DO_ENDPOINT'),
'directory_env' => env('DO_DIRECTORY'),
'use_path_style_endpoint' => env('DO_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'bucket_endpoint' => true,
'visibility' => 'public',
],
'do' => [
'driver' => 's3',
'key' => env('DO_ACCESS_KEY_ID'),
'secret' => env('DO_SECRET_ACCESS_KEY'),
'region' => env('DO_DEFAULT_REGION'),
'bucket' => env('DO_BUCKET'),
'url' => env('DO_URL'),
'endpoint' => env('DO_ENDPOINT'),
'directory_env' => env('DO_DIRECTORY'),
'use_path_style_endpoint' => env('DO_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'bucket_endpoint' => true,
'visibility' => 'public',
],
DO_DIRECTORY=local
DO_DIRECTORY=local
No description
Solution:
So that would usually be set with: 'root' => env('DO_DIRECTORY', 'local/images'),...
Jump to solution
12 Replies
toeknee
toeknee4mo ago
This isn't random this is intentional. This is Spatie Media for you and how it works. The number is the reference to the database record and you should have a bucket soley for spatie media. I have created several s3 drivers with different folders when I want to group by folder
Cushty
CushtyOP4mo ago
Thanks for the reply, yes i understand that Spatie puts it in folders like that but I want these folders in a directory on DO, so 33 and 34 will be in a directory called local/images, but they are not in a directory at all, and I cant get it to work, can you shed some light? Thanks
toeknee
toeknee4mo ago
Because you need to set the directory there in the driver usually
Cushty
CushtyOP4mo ago
I have in the driver 'directory_env' => env('DO_DIRECTORY'),
Solution
toeknee
toeknee4mo ago
So that would usually be set with: 'root' => env('DO_DIRECTORY', 'local/images'),
Cushty
CushtyOP4mo ago
Ah, I will try it that way direct in the driver Can I ask why you are setting default here? 'DO_DIRECTORY', 'local/images I thought the code I did will work as well, thanks
toeknee
toeknee4mo ago
Incase one hasn’t been defined it makes sense to set a default
Cushty
CushtyOP4mo ago
Sorry if I am getting cofused but wont 'root' => be the same as setting 'directory_env' =>
toeknee
toeknee4mo ago
Last time I checked directory_env didn’t work in S3 driver type and requires root
Cushty
CushtyOP4mo ago
Wow, you are probably right, I was following this tutorial and adding custom code to s3 driver worked for him, so strange https://youtu.be/jW3qjVTQl6Y?si=u7-PqRNbT1DL5epf&t=956 I skipped to the part he adds the custom code. Will try root now
Code With Dary
YouTube
How to Use DigitalOcean Spaces in Laravel & FilamentPHP | How to Us...
In this tutorial, we dive into how to use DigitalOcean Spaces to store and manage files from your Filament application. We'll start by understanding what DigitalOcean Spaces is and why it's a valuable addition to your storage solutions. From there, we'll guide you through setting up a connection between DigitalOcean Spaces and a Laravel applicat...
Cushty
CushtyOP4mo ago
sorry starts at 15:45 adding root. works!!! how did it work for him lol Thanks for your help, do you know why it worked for him?
toeknee
toeknee4mo ago
I’m not sure it did tbh… But it could be how we handle the upload I’m not too sure
Want results from more Discord servers?
Add your server