Can't preview an image with 'private' disk when using spatie-laravel-media-library-plugin

Hi, I have field like this
SpatieMediaLibraryFileUpload::make('business_license')
->collection('business-license')
->disk('private')
->image()
->visibility('private')
->label(__('Business License'))
->maxSize(1024),
SpatieMediaLibraryFileUpload::make('business_license')
->collection('business-license')
->disk('private')
->image()
->visibility('private')
->label(__('Business License'))
->maxSize(1024),
, Uploading works fine. But I can't preview this image when I view/edit the reocrd. here is the disk in my 'config/filesystems.php':
'private' => [ //For private files
'driver' => 'local',
'root' => storage_path('app/private'), // Important: Different directory!
'url' => env('APP_URL').'/private', // It is important to set url, otherwise, error may occur.
'visibility' => 'private',
],
'private' => [ //For private files
'driver' => 'local',
'root' => storage_path('app/private'), // Important: Different directory!
'url' => env('APP_URL').'/private', // It is important to set url, otherwise, error may occur.
'visibility' => 'private',
],
. On the model, I do have this block
$this
->addMediaCollection('business-license') // Collection for the business license
->useDisk('private')
->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/jpg'])
->singleFile(); // Enforce that only one file can be in this collection
$this
->addMediaCollection('business-license') // Collection for the business license
->useDisk('private')
->acceptsMimeTypes(['image/jpeg', 'image/png', 'image/jpg'])
->singleFile(); // Enforce that only one file can be in this collection
. I checked the document "One way to store files privately is to configure this in your S3 bucket settings, in which case you should also use visibility('private') to ensure that Filament generates temporary URLs for your files.", but I just use a local 'private' disk. any insights on how to let 'Filament generates temporary URLs ' for my loal private files? thanks
4 Replies
sweetplum
sweetplumOP2mo ago
help!
Batman
Batman2mo ago
Is your APP_URL is correct? This gets me a lot. For my setup I need the port when running locally via composer run dev:
APP_URL=http://127.0.0.1:8000
APP_URL=http://127.0.0.1:8000
Dennis Koch
Dennis Koch2mo ago
but I just use a local 'private' disk. any insights on how to let 'Filament generates temporary URLs ' for my loal private files? thanks
You need to tell your disk how to generate private images and add a controller that serves those images.
Dennis Koch
Dennis Koch2mo ago
File Storage - Laravel 12.x - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.

Did you find this page helpful?