适用于AWS S3 php-sdk"putObjectAcl"的正确语法 [英] Proper syntax for AWS S3 php-sdk "putObjectAcl"

查看:88
本文介绍了适用于AWS S3 php-sdk"putObjectAcl"的正确语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是弄清楚AWS PHP sdk的工作方式,因此我们可以使用它来托管Web服务器的客户图像数据.我已经能够成功测试创建,管理数据以及将数据加载到存储桶中的大多数功能,但是当我尝试查看内容时,会出现访问被拒绝"的信息.

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.

但是,无论我如何尝试遵循PHP sdk [limited]文档中的示例,我似乎都无法使用Amazon提供的php代码设置ACL值.

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.

他们的示例只是在各个值的位置列出,而我尝试为其中的存储桶,对象和帐户填写相关数据,但这是行不通的.我尝试做一个 getObjectAcl 并发送回类似于收到的内容,但它不起作用.我尝试过在线查看示例,但发现的内容却不起作用.

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);

结果输出:

致命错误:未捕获的异常'Aws \ S3 \ Exception \ S3Exception'与消息在执行"PutObjectAcl"时出错 https://我们的测试桶.s3.us-east-2.amazonaws.com/800x600.jpg?acl ";AWS HTTP错误:客户端错误: PUThttps://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl 导致/project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php在第191行

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:在" https://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl ";AWS HTTP错误:客户端错误: PUThttps://our-test-bucket.s3.us-east-2.amazonaws.com/800x600.jpg?acl 导致 400错误的请求响应: MalformedACLError 您提供的XML格式不正确(被截断了...)MalformedACLError(客户端):您提供的XML格式不正确或未针对我们发布的架构进行验证- MalformedACLError 您提供的XML格式不正确或未针对我们发布的XML进行验证schemaB24661919936C2DADft/******************************************************* =在/project/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php中在线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

推荐答案

我设法将跟踪放入html消息messageTrait withHeader()函数中,以便可以查看php流中的传出xml.然后,我将结果与在google搜索的各个位置找到的xml的示例进行了比较,并通过反复试验与比较,将问题归结为'DisplayName'=>'All Users'在小组资助中.删除该行,它似乎可以正常工作.

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)

这篇关于适用于AWS S3 php-sdk"putObjectAcl"的正确语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆