F
Filament8mo ago
srjrol

How to use private local storage with ImageEntry

How do I setup private local storage so I can store images that are not publicly accessible and load them via ImageEntry? I tried specifying the ->disk('private') but its not working. Do I need to create a Controller and if so how should that be used with ImageEntry? I tried like ->url(fn ($record) => route('secure-images.show', ['filename' => $record->image_url])) but this isn't working for me either.
I also tried using ->visibility('private') but I'm not having any luck wth that either...
Solution:
Not really sure, but I think you also need to specify ->visibility('private') on the ImageEntry?
Jump to solution
3 Replies
srjrol
srjrolOP8mo ago
I found a similar question/answer https://discord.com/channels/883083792112300104/1145723690839973908 but it's not working for me.
@CodeWithDennis Do you have any suggestions for what I could be missing here? Thanks The documentation says "The entry must contain the path to the image, relative to the root directory of its storage disk, or an absolute URL to it." and I've stored the images in my providers image_url column with the relative path like provider-images/01HWX.jpg In my AppServiceProvider.php I am using buildTemporaryUrlsUsing as instructed:
public function boot(): void
{
Storage::disk('private')->buildTemporaryUrlsUsing(function ($path, $expiration, $options = []) {
return URL::temporarySignedRoute(
'private.temp',
$expiration,
array_merge($options, ['path' => $path])
);
});
}
public function boot(): void
{
Storage::disk('private')->buildTemporaryUrlsUsing(function ($path, $expiration, $options = []) {
return URL::temporarySignedRoute(
'private.temp',
$expiration,
array_merge($options, ['path' => $path])
);
});
}
In my ViewProvider.php the ImageEntry->url() works as expected and I can see the image if I visit that URL directly but the image is still not loading from the image_url column in my database
$imageUrl = Storage::disk('private')->temporaryUrl(
$this->record->image_url,
now()->addMinutes(60)
);

ImageEntry::make('image_url')
->disk('private')
->url($imageUrl)
$imageUrl = Storage::disk('private')->temporaryUrl(
$this->record->image_url,
now()->addMinutes(60)
);

ImageEntry::make('image_url')
->disk('private')
->url($imageUrl)
EditProvider.php is correctly storing images in /storage/app/private/provider-images/ web.php (using ->where('path', '.*') as @CodeWithDennis suggested.
Route::get('private/temp/{path}', [ImageController::class, 'show'])
->where('path', '.*')
->name('private.temp');
Route::get('private/temp/{path}', [ImageController::class, 'show'])
->where('path', '.*')
->name('private.temp');
In the logs I can see the URL is generated as I expect but the image fails to load because it's trying from https://mydomain.com/storage/provider-images/01HWX.jpg instead of the ->url() path like https://mydomain.com/private/temp/provider-images/01HWXQR459X1ABFQTHPQV9DACQ.jpg?expires=1714749092&signature=73a61b...
Solution
Dennis Koch
Dennis Koch8mo ago
Not really sure, but I think you also need to specify ->visibility('private') on the ImageEntry?
srjrol
srjrolOP8mo ago
Thanks, I can't belive that was it >.< I thought that would cause a conflict since I am creating temporary urls already manually.
Want results from more Discord servers?
Add your server