forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths3ObjectAcl.php
More file actions
74 lines (66 loc) · 1.93 KB
/
Copy paths3ObjectAcl.php
File metadata and controls
74 lines (66 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// snippet-start:[s3.php.object_acl.complete]
// snippet-start:[s3.php.object_acl.import]
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
// snippet-end:[s3.php.object_acl.import]
// Create a S3Client
// snippet-start:[s3.php.object_acl.main]
$s3Client = new S3Client([
'region' => 'us-west-2',
'version' => '2006-03-01'
]);
// Gets the access control list (ACL) of an object.
$bucket = 'amzn-s3-demo-bucket';
$key = 'my-object';
try {
$resp = $s3Client->getObjectAcl([
'Bucket' => $bucket,
'Key' => $key,
]);
echo "Succeed in retrieving object ACL as follows: \n";
var_dump($resp);
} catch (AwsException $e) {
// output error message if fails
echo $e->getMessage();
echo "\n";
}
// Use acl subresource to set the access control list (ACL) permissions
// for an object that already exists in a bucket
$params = [
'ACL' => 'public-read',
'AccessControlPolicy' => [
// Information can be retrieved from `getObjectAcl` response
'Grants' => [
[
'Grantee' => [
'DisplayName' => '<string>',
'EmailAddress' => '<string>',
'ID' => '<string>',
'Type' => 'CanonicalUser',
'URI' => '<string>',
],
'Permission' => 'FULL_CONTROL',
],
],
'Owner' => [
'DisplayName' => '<string>',
'ID' => '<string>',
],
],
'Bucket' => $bucket,
'Key' => $key,
];
try {
$resp = $s3Client->putObjectAcl($params);
echo "Succeed in setting object ACL.\n";
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
// snippet-end:[s3.php.object_acl.main]
// snippet-end:[s3.php.object_acl.complete]