I'm having a problem using s3 storage driver in Laravel filament. I'm getting this exception:
League \ Flysystem \ UnableToCheckDirectoryExistence
Unable to check existence for: https:/spaces.link/bucket-name/posts/istockphoto-457796927-612x612.jpg
I'm using Digital Ocean spaces to store images. I can load this image by going to the URL just fine. Only thing I noticed, is that the protocol part in URL is missing one /, so instead of https:// it's actaully https:/. I assume that is the reason for this erorr, but unfortunatelly, I can't find a way to fix it. Here's the setup of my code:
.env:
DO_SPACES_KEY=key
DO_SPACES_SECRET=secret
DO_SPACES_ENDPOINT=https://spaces.url
DO_SPACES_REGION=fra1
DO_SPACES_BUCKET=bucket.name
DO_SPACES_USE_PATH_STYLE_ENDPOINT=true
filesystems.php
's3' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
'use_path_style_endpoint' => env('DO_SPACES_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
'visibility' => 'public',
],
This is how I retrieve the image url:
return Storage::disk('s3')->url($featuredImage->path);
If I do a dd() of this value, I get the correct link with two // in the protocol. But the same exception occurs. If I comment out this value, I get no exception.
"https://spaces.link/bucket.name/posts/istockphoto-457796927-612x612.jpg" // app/Models/Post.php:103
If it is relevant in any way, I created a getter for this in the Post.php model, and this is where I get the mentioned exception:
protected function featuredImage(): Attribute{
return Attribute::make(
get: fn () => $this->getFeaturedImage(),
);
}
public function getFeaturedImage(){
$featuredImage = $this->images()->where('featured', true)->first();
if($featuredImage){
return Storage::disk('s3')->url($featuredImage->path);
}
return null;
}
public function images(){
return $this->hasMany(PostImage::class, 'post_id');
}
When I remove the getter, everything work just fine.
Any help is appreciated.