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 191Aws\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 a400 Bad Request
response:MalformedACLError
The 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 -MalformedACLError
The 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