Laravel has built-in support for retrieving images from S3. It seems that you're using some kind of custom way to do this. You can read more about it here: https://laravel.com/docs/7.x/filesystem#file-urls
Laravel 7 - The image object from S3 is fetched but cannot be displayed
Added more information based on L7 docs at the bottom.
I am successfully able to upload the file to S3 and get the object URI. However when the URI is put in the image tag, it shows a broken image. I can print the raw URI in my view as well as using dd. The $logoname below is pulled from a database query.
$logoname = $company->logo;
$destinationPath = "logos/";
$value = $destinationPath.$logoname;
$disk = Storage::disk('s3');
if (isset($logoname)) {
if ($disk->exists($value)) {
$command = $disk->getDriver()->getAdapter()->getClient()->getCommand('GetObject', [
'Bucket' => env('S3_BUCKET'),
'Key' => $value
]);
$request = $disk->getDriver()->getAdapter()->getClient()->createPresignedRequest($command, '+200 minutes');
$myuri = (string) $request->getUri();
return view('company', compact(['myuri']
}
}
Based on Laravel 7 docs - as suggested by @bobbybouwmann below I have also attempted the following:
$myuri = Storage::get($value);
$myuri = $disk->get($value);
$myuri = Storage::disk('s3')->get($value);
$myuri = Storage::disk('s3')->url($value);
$myuri = Storage::disk('s3')->temporaryUrl( $value, now()->addMinutes(5), ['ResponseContentType' => 'application/octet-stream'] );
I have even set the bucket to public access.
Error if the URL pasted in browser:
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>logos/phpSOzViN1598729897lyoDFyBoLJssn7Dbrf9ORHTV44fyr8xpOwmDSUzN6AgJDVtyZvqs4MRw2dNKFJgPvdl2UpUu6AORscvJ.jpg</Key>
<RequestId>a small string </RequestId>
<HostId>a long string with a host id</HostId>
</Error>
Please or to participate in this conversation.