set_object_acl ( $bucket, $filename, $acl, $opt )

Sets the access control list (ACL) settings for the specified Amazon S3 object.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$filename

string

Required

The file name for the object.

$acl

string

Optional

The ACL settings for the specified object. Accepts any of the following constants: [Allowed values: AmazonS3::ACL_PRIVATE, AmazonS3::ACL_PUBLIC, AmazonS3::ACL_OPEN, AmazonS3::ACL_AUTH_READ, AmazonS3::ACL_OWNER_READ, AmazonS3::ACL_OWNER_FULL_CONTROL]. Alternatively, an array of associative arrays. Each associative array contains an id and a permission key. The default value is ACL_PRIVATE.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Examples

Set a canned ACL setting on an object.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->set_object_acl($bucket, 'test1.txt', AmazonS3::ACL_PUBLIC);

// Success?
var_dump($response->isOK());
Result:
bool(true)

Set a custom ACL setting on an object.

// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

$response = $s3->set_object_acl($bucket, 'test1.txt', array(
	array( 'id' => AmazonS3::USERS_AUTH,               'permission' => AmazonS3::GRANT_READ         ), // Authenticated users, READ
	array( 'id' => CFCredentials::get()->canonical_id, 'permission' => AmazonS3::GRANT_FULL_CONTROL )  // Self, FULL_CONTROL
));

// Success?
var_dump($response->isOK());
Result:
bool(true)

See Also

Source

Method defined in services/s3.class.php | Toggle source view (42 lines) | View on GitHub

public function set_object_acl($bucket, $filename, $acl = self::ACL_PRIVATE, $opt = null)
{
    // Add this to our request
    if (!$opt) $opt = array();
    $opt['verb'] = 'PUT';
    $opt['resource'] = $filename;
    $opt['sub_resource'] = 'acl';
    // Retrieve the original metadata
    $metadata = $this->get_object_metadata($bucket, $filename);
    if ($metadata && $metadata['ContentType'])
    {
        $opt['headers']['Content-Type'] = $metadata['ContentType'];
    }
    if ($metadata && $metadata['StorageClass'])
    {
        $opt['headers']['x-amz-storage-class'] = $metadata['StorageClass'];
    }

    // Make sure these are defined.
    // @codeCoverageIgnoreStart
    if (!$this->credentials->canonical_id || !$this->credentials->canonical_name)
    {
        // Fetch the data live.
        $canonical = $this->get_canonical_user_id();
        $this->credentials->canonical_id = $canonical['id'];
        $this->credentials->canonical_name = $canonical['display_name'];
    }
    // @codeCoverageIgnoreEnd

    if (is_array($acl))
    {
        $opt['headers'] = array_merge($opt['headers'], $this->generate_access_policy_headers($acl));
    }
    else
    {
        $opt['body'] = '';
        $opt['headers']['x-amz-acl'] = $acl;
    }

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback