如何防止文件在数字海洋空间公开?

问题描述

大家好,我坚持使用 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 中的可见性设置为 public。无需身份验证即可查看文件

预先感谢您提供任何帮助或建议。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...