大家好,我在 Digital Ocean 上想阻止我的文件公开。
首先。我像这样设置 .env 文件
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
然后我设置 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',
],
之后让控制器存储文件
//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();
在我的刀片模板上,我像这样检索文件
{{ Storage::disk('do_spaces')->url('public/user_image/'.$user->image) }}
当我没有将可见性设置为公开时,这就是我得到的
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>
如果我将 filesystem.php 中的可见性设置为公开。我可以在没有身份验证的情况下查看文件。
提前感谢您的任何帮助或建议。