Hi everyone I stuck on Digital Ocean that I want to prevent my file from the public.
First of all. I set the .env file like this
DO_SPACES_KEY= THE KEY
DO_SPACES_SECRET= THE SECRET
DO_SPACES_ENDPOINT=https://sgp1.digitaloceanspaces.com
DO_SPACES_REGION=sgp1
DO_SPACES_BUCKET= MY BUCKET NAME
DO_SPACES_URL=https://mydomain.sgp1.digitaloceanspaces.com
Then I set the config->filesystem.php
'do_spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
'url' => env('DO_SPACES_URL'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'visibility' => 'public',
],
After that make the controller store the file
//convert image name
$stringImageReFormat=base64_encode('_'.time());
$ext=$request->file('image')->getClientOriginalExtension();
$imageName=$stringImageReFormat.".".$ext;
$imageEncoded=File::get($request->image);
//upload & insert
Storage::disk('do_spaces')->put('public/user_image/'.$imageName,$imageEncoded);
// Insert Data to Table
$user=new User();
$user->image=$imageName;
$user->save();
On my blade template, I retrieve the file like this
{{ Storage::disk('do_spaces')->url('public/user_image/'.$user->image) }}
This is what I get when I don't set the visibility to public
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>AccessDenied</Code>
<BucketName>mybucket</BucketName>
<RequestId>tx0000000000000088d0617-00607228ae-13200e4-sgp1b</RequestId>
<HostId>13200e4-sgp1b-sgp1-zg02</HostId>
</Error>
If I set the visibility in the filesystem.php to public. I can see the files without authentication.
Thank you in advance for any help or advice.