Show S3 image
I'm having trouble showing the S3 file.
I can upload, but I can not show in a view for the user.
Controller
/* Upload Cover IMG */
if($request->hasFile('cover')){
$file = $request->file('cover');
$name = time().$file->getClientOriginalName();
$filepath = 'programs/cover/'.$name;
Storage::disk('s3')->put($filepath, file_get_contents($file), 'public');
}
In the database column is thus the reference of the image
/tmp/phprLfowL
showing? you have told us the code to STORE.. where is the code to SHOW?
Storage::disk('s3')->put($filepath, file_get_contents($file), 'public');
$url = Storage::disk('s3')->url($filepath.$name);
$dataForm['cover'] = $url;
here I save the image in S3 and save the url of this img in the database, and the image now becomes as access denied.
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>CB10E66148C86E20</RequestId>
<HostId>yyDeDny2VMP/hI+4qbztrlHM+05reCalJ4ji3zGeVYkaDaU6hLNTVDNKmSJtEzDrOUMhoIv9piU=</HostId>
</Error>
I am not an S3 expect by any stretch of the imagination, but here a few things I learned with limited experience.
- Make sure you have proper permissions on the bucket & its folders
- Depending on the above permissions you sometimes have grant a url that is valid for a certain amount of time per item.
These are "generally" the issues I ran into. I would double check the documentation to S3 to make sure you have things configured properly.
Resolved
Storage::disk('s3')->put($filepath, file_get_contents($file), 'public');
$url = Storage::disk('s3')->url($filepath);
$dataForm['cover'] = $url;
Please or to participate in this conversation.