duanqianhuan3994 2016-02-23 06:51
浏览 78
已采纳

在AWS s3文件夹上载期间ACL未应用(uploadDirectory)

For some reason public-read is not being applied when I'm uploading a folder to an S3 bucket. (IE, public can not access the files)

The files upload fine, but they are all set to private. Tried everything I can think of. Feels like I'm missing something basic.

Was using this guide: https://blogs.aws.amazon.com/php/post/Tx2W9JAA7RXVOXA/Syncing-Data-with-Amazon-S3

Here is my code:

    require '../vendor/autoload.php';

    use Aws\S3\S3Client;

    $client = S3Client::factory(array(  
      'version' => '2006-03-01',
      'region'  => 'ap-southeast-2',
      'credentials' => array(
        'key' => 'MYKEY',
        'secret'  => 'MYSECRET',        
      )
    ));    

    $dir = 'assets';
    $bucket = 'gittestbucket';
    $keyPrefix = 'assets';      

    $options = array(
        'params'      => array('ACL' => 'public-read'),
        'concurrency' => 20,
        'debug'       => true
    );

    $UploadAWS = $client->uploadDirectory($dir, $bucket, $keyPrefix, $options);

    var_dump($UploadAWS);

My IAM user policy (also has a group of list all buckets):

    {
        "Statement": [
            {
                "Action": "s3:*",
                "Effect": "Allow",
                "Resource": [
                    "arn:aws:s3:::gittestbucket",
                    "arn:aws:s3:::gittestbucket/*",              
                ]
            }
        ]
    }

Any help much appreciated. Cheers

  • 写回答

1条回答 默认 最新

  • dstnlhhv791576 2016-02-23 22:38
    关注

    I struggled with this a while back.

    Try changing you upload statement to this one bellow

     $UploadAWS = $client->uploadDirectory($dir, $bucket, $keyPrefix, array(
            'concurrency' => 20,
            'debug'       => true,
            'before' => function (\Aws\Command $command) {
            $command['ACL'] = strpos($command['Key'], 'CONFIDENTIAL') === false
                ? 'public-read'
                : 'private';
            }
        ));
    

    AWS is shocking sometimes for its documentation as it changes so much

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向