php - How to access private files stored in Amazon s3 bucket and display in Laravel blade
one text
I have a profile page where user uploads their driving license image, I'm storing these images in Amazon s3 bucket with private visibility $path = $request->file('image')->store('avatars', 's3')
. I want to display this image in user profile page, As the files are private to access these images i found solution that i have to create temporary URLs to access the image as follows
$image_path = Storage::disk('s3')->temporaryUrl(
'avatars/'.$license->imageName,
Carbon::now()->addMinutes(20)
);
The $image_path
is returning me temporary path of url which I can use in <img src="{{$image_path}}"
tag but issue with this solution is even if I copy and paste this temporary url in incognito mode its returning the image , as 20 minutes time is set , this solution my client is not accepting as image is accessible in private window even though its temporary access.
another solution that i found without generating temporary url is by using return $src = Storage::disk('s3')->response('avatars/'.$image->filename);
if i return this line it will print image in the browser. but i want do display image in the blade file if i print this $src
in the blade file {{src}}
is outputing HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Disposition: inline; filename=vkMv0NcQGBoq3U9C7DUNhzujA6tLEp8dQEIMJCO2.jpg Content-Length: 1630 Content-Type: image/jpeg Date: Wed, 03 Nov 2021 10:07:56 GMT
.
Please guide is there any way i can print these image in blade , or any other way to access private files without generating temporary urls
Source