doutui7955 2019-03-04 17:17
浏览 322

适用于AWS S3的语法php-sdk“putObjectAcl”

I've been tasked with figuring out how the AWS PHP sdk works so we can possibly use it for hosting customer image data for our web server. I've been able to successfully test most of the functionality of creating, managing and loading data into a bucket, but when I try to view the contents I get 'access denied'.

Going into the management console, I figured out how to set the permissions so I could view the file, either with a specific host rule or by setting both the bucket and the object world-readable.

However, no matter how I try following the examples in the PHP sdk [limited] documentation, I cannot seem to set the ACL values using the php code provided by Amazon.

Their examples just list in the place of the various value and I have tried filling in the relevant data for my bucket, object and account in those and it doesn't work. I've tried doing a getObjectAcl and sending back something similar to what was received and it doesn't work. I've tried looking at examples on-line and what little I have found doesn't work.

Here's an example of the latest I have tried:

$params = [
    'ACL' => 'public-read',
    'AccessControlPolicy' => [
        'Grants' => [
            [
                'Grantee' => [
                    'DisplayName' => 'Owner',
                    'ID' => $awsId,
                    'Type' => "CanonicalUser"
                ],
                'Permission' => "FULL_CONTROL"
            ],
            [
                'Grantee' => [
                    'DisplayName' => 'All Users',
                    'URI' => "http://acs.amazonaws.com/groups/global/AllUsers",
                    'Type' => "Group"
                ],
                'Permission' => "READ"
            ],
        ],
        'Owner' => [
            'ID' => $awsId
        ]
    ],
    'Bucket' => "our-test-bucket",
    'Key' => "800x600.jpg"
];

$result = $awsSdk->getS3Client()->putObjectAcl($params);

The resulting output:

Fatal error: Uncaught exception 'Aws\S3\Exception\S3Exception' with message 'Error executing "PutObjectAcl" on "https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl"; AWS HTTP error: Client error: PUT https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl resulted in /project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191

Aws\S3\Exception\S3Exception: Error executing "PutObjectAcl" on "https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl"; AWS HTTP error: Client error: PUT https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl resulted in a 400 Bad Request response: MalformedACLErrorThe XML you provided was not well-f (truncated...) MalformedACLError (client): The XML you provided was not well-formed or did not validate against our published schema - MalformedACLErrorThe XML you provided was not well-formed or did not validate against our published schemaB24661919936C2DADft/***********************************************= in /project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 191

  • 写回答

1条回答 默认 最新

  • drnzpd579935 2019-03-06 16:32
    关注

    I managed to drop a trace into the guzzle html messageTrait withHeader() function so I could watch the outgoing xml in the php stream. I then compared the result with examples of the xml I found in various places in a google search and through trial and error with the comparisons, I traced the problem down to the 'DisplayName' => 'All Users' in the Group Grant. Remove that line and it appears to work.

    $pubAcl = [
        'Owner' => [
            'ID' => $awsId,
            'DisplayName' => 'Owner'
        ],
        'Grants' => [
            [
                'Grantee' => [
                    'ID' => $awsId,
                    'DisplayName' => 'Owner',
                    'Type' => "CanonicalUser"
                ],
                'Permission' => "FULL_CONTROL"
            ],
            [
                'Grantee' => [
                    'URI' => "http://acs.amazonaws.com/groups/global/AllUsers",
                    'Type' => "Group"
                ],
                'Permission' => "READ"
            ]
        ]
    ];
    

    (The order change was the result of testing but didn't turn out to be the problem)

    评论

报告相同问题?

问题事件

  • 专家修改了标签 8月18日

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况