initiate_multipart_upload ( $bucket, $filename, $opt )

Initiates a multipart upload and returns an UploadId.

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.

$opt

array

Optional

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

  • 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.
  • contentType - string - Optional - The type of content that is being sent. The default value is application/octet-stream.
  • encryption - string - Optional - The algorithm to use for encrypting the object. [Allowed values: AES256]
  • headers - array - Optional - Standard HTTP headers to send along in the request. Accepts an associative array of key-value pairs.
  • meta - array - Optional - An associative array of key-value pairs. Any header starting with x-amz-meta-: is considered user metadata. It will be stored with the object and returned when you retrieve the object. The total size of the HTTP request, not including the body, must be less than 4 KB.
  • storage - string - Optional - Whether to use Standard or Reduced Redundancy storage. [Allowed values: AmazonS3::STORAGE_STANDARD, AmazonS3::STORAGE_REDUCED]. The default value is STORAGE_STANDARD.
  • 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

Initiate a new multipart upload.

  1. Initiate a new multipart upload using initiate_multipart_upload().
  2. Upload the parts using upload_part().
  3. Complete the upload using complete_multipart_upload().
// Instantiate the class
$s3 = new AmazonS3();
$bucket = 'my-bucket' . strtolower($s3->key);

// Initiate a new multipart upload
$response = $s3->initiate_multipart_upload($bucket, 'movie.mp4', array(
	'contentType' => 'video/mp4',
	'acl'         => AmazonS3::ACL_PUBLIC,
	'storage'     => AmazonS3::STORAGE_STANDARD,
	'meta'        => array(
		'resolution' => '720p',
		'rating'     => 'US PG-13',
		'runtime'    => '2:04:37'
	)
));

// Get the Upload ID
$upload_id = (string) $response->body->UploadId;

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

See Also

Source

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

public function initiate_multipart_upload($bucket, $filename, $opt = null)
{
    if (!$opt) $opt = array();

    // Add this to our request
    $opt['verb'] = 'POST';
    $opt['resource'] = $filename;
    $opt['sub_resource'] = 'uploads';
    $opt['body'] = '';

    // Handle content type. Can also be passed as an HTTP header.
    if (isset($opt['contentType']))
    {
        $opt['headers']['Content-Type'] = $opt['contentType'];
        unset($opt['contentType']);
    }

    // Set a default content type.
    if (!isset($opt['headers']['Content-Type']))
    {
        $opt['headers']['Content-Type'] = 'application/octet-stream';
    }

    // Handle Access Control Lists. Can also be passed as an HTTP header.
    if (isset($opt['acl']))
    {
        if (is_array($opt['acl']))
        {
            $opt['headers'] = array_merge($opt['headers'], $this->generate_access_policy_headers($opt['acl']));
        }
        else
        {
            $opt['headers']['x-amz-acl'] = $opt['acl'];
        }
    }

    // Handle storage settings. Can also be passed as an HTTP header.
    if (isset($opt['storage']))
    {
        $opt['headers']['x-amz-storage-class'] = $opt['storage'];
        unset($opt['storage']);
    }

    // Handle encryption settings. Can also be passed as an HTTP header.
    if (isset($opt['encryption']))
    {
        $opt['headers']['x-amz-server-side-encryption'] = $opt['encryption'];
        unset($opt['encryption']);
    }

    // Handle meta tags. Can also be passed as an HTTP header.
    if (isset($opt['meta']))
    {
        foreach ($opt['meta'] as $meta_key => $meta_value)
        {
            // e.g., `My Meta Header` is converted to `x-amz-meta-my-meta-header`.
            $opt['headers']['x-amz-meta-' . strtolower(str_replace(' ', '-', $meta_key))] = $meta_value;
        }
        unset($opt['meta']);
    }

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

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback