Spatie Media Library / Downloading images as damaged
Hello friends,
I am facing a problem with Spatie Media Library download images from a remote server. I would like to take your opinion and guidance where would I look into to try to find the source of the problem.
In my app, I make use of S3 driver to upload/download files to Digital Ocean Spaces.
One of the disks I have that I am using with Spatie Media library has the following settings:
'tasks' => [
'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'),
'use_path_style_endpoint' => env('DO_USE_PATH_STYLE_ENDPOINT', false),
'throw' => false,
],
All environment variables are defined inside the .env file.
Uploading works just fine. I can even open the files from within the DO Spaces.
However, when I try to download or stream a file from DO Spaces using spatie media library, I get damaged image files. The size of the images matches that of the original image, but I can't open it.
To inline stream the image, I simply use this:
public function show(Media $media)
{
return $media;
}
I tried downloading the file instead using:
return response()->download($media->getPath(), $media->file_name);
I would get an exception that file doesn't exist:
\teams\....\the-image.png
Is there anything that I might need to configure to make sure the download works well?
One thing to mention I make use of the DO Spaces CDN. The original URL still exists and functions properly.
I thank you for your time reading this post and hopefully we could solve it somehow :-)
Regards Bilal
Please or to participate in this conversation.