upload_part ( $bucket, $filename, $upload_id, $opt )

Uploads a single part of a multipart upload. The part size cannot be smaller than 5 MB or larger than 5 TB. A multipart upload can have no more than 10,000 parts.

Amazon S3 charges for storage as well as requests to the service. Smaller part sizes (and more requests) allow for faster failures and better upload reliability. Larger part sizes (and fewer requests) costs slightly less but has lower upload reliability.

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.

$upload_id

string

Required

The upload ID identifying the multipart upload whose parts are being listed. The upload ID is retrieved from a call to initiate_multipart_upload().

$opt

array

Optional

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

  • fileUpload - string|resource - Required - The URL/path for the file to upload or an open resource.
  • partNumber - integer - Required - The part number order of the multipart upload.
  • expect - string - Optional - Specifies that the SDK not send the request body until it receives an acknowledgement. If the message is rejected based on the headers, the body of the message is not sent. For more information, see RFC 2616, section 14.20. The value can also be passed to the header option as Expect. [Allowed values: 100-continue]
  • headers - array - Optional - Standard HTTP headers to send along in the request. Accepts an associative array of key-value pairs.
  • length - integer - Optional - The size of the part in bytes. For more information, see RFC 2616, section 14.13. The value can also be passed to the header option as Content-Length.
  • md5 - string - Optional - The base64 encoded 128-bit MD5 digest of the part data. This header can be used as a message integrity check to verify that the part data is the same data that was originally sent. Although it is optional, we recommend using this mechanism as an end-to-end integrity check. For more information, see RFC 1864. The value can also be passed to the header option as Content-MD5.
  • seekTo - integer - Optional - The starting position in bytes for the piece of the file/stream to upload.
  • 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

Upload parts of a file in sequence.

  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().
// Define a mebibyte
define('MB', 1024 * 1024);

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

// Get the list of pieces
$parts = $s3->get_multipart_counts(filesize('movie.mp4'), 50*MB);

// Queue batch requests
foreach ($parts as $i => $part)
{
	$s3->batch()->upload_part($bucket, 'movie.mp4', 'f_JM_zwhU37pj1tS.F2BXVWUJtGcNso1WEikZImjrBCYUbUQwNnOUwX.Z00O1QmKQXAjqQBD4BVZRGmEXAMPLE--', array(
		'expect'     => '100-continue',
		'fileUpload' => 'movie.mp4',
		'partNumber' => ($i + 1),
		'seekTo'     => (integer) $part['seekTo'],
		'length'     => (integer) $part['length'],
	));
}

// Send batch requests
$batch_responses = $s3->batch()->send();

// Success?
var_dump($batch_responses->areOK());
Result:
bool(true)

Related Methods

Source

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

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

    // Add this to our request
    $opt['verb'] = 'PUT';
    $opt['resource'] = $filename;
    $opt['uploadId'] = $upload_id;

    if (!isset($opt['fileUpload']) || !isset($opt['partNumber']))
    {
        throw new S3_Exception('The `fileUpload` and `partNumber` options are both required in ' . __FUNCTION__ . '().');
    }

    // Handle expectation. Can also be passed as an HTTP header.
    if (isset($opt['expect']))
    {
        $opt['headers']['Expect'] = $opt['expect'];
        unset($opt['expect']);
    }

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

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

    $opt['headers']['Expect'] = '100-continue';

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

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback