Skip to content

Commit

Permalink
Allow streams for multipart uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Uranium235 committed Dec 28, 2010
1 parent 130d4e6 commit 340f030
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions services/s3.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3539,6 +3539,7 @@ public function list_multipart_uploads($bucket, $opt = null)
* contentType - _string_ (Optional) The type of content that is being sent in the body. The default value is `application/octet-stream`.
* headers - _array_ (Optional) The standard HTTP headers to send along in the request.
* 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.
* length - _integer_ (Optional) The size of the object in bytes. For more information, see [RFC 2616, section 14.13](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13). The value can also be passed to the `header` option as `Content-Length`.
* partSize - _integer_ (Optional) The size of an individual part. The size may not be smaller than 5 MB or larger than 500 MB. The default value is 50 MB.
* 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>.
* uploadId - _string_ (Optional) An upload ID identifying an existing multipart upload to use. If this option is not set, one will be created automatically.
Expand All @@ -3558,14 +3559,43 @@ public function create_mpu_object($bucket, $filename, $opt = null)
throw new S3_Exception(__FUNCTION__ . '() cannot be batch requested');
}

if (!$opt) $opt = array();

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

if (!isset($opt['fileUpload']))
{
throw new S3_Exception('The `fileUpload` option is required in ' . __FUNCTION__ . '().');
}
elseif (is_resource($opt['fileUpload']))
{
throw new S3_Exception('The `fileUpload` option cannot be a resource in ' . __FUNCTION__ . '().');
$opt['limit'] = 1; // We can only read from this one resource.
$upload_position = ftell($opt['fileUpload']);
$upload_filesize = isset($opt['headers']['Content-Length']) ? $opt['headers']['Content-Length'] : null;

if (!isset($upload_filesize) && $upload_position !== false)
{
$stats = fstat($opt['fileUpload']);
if ($stats && $stats['size'] >= 0)
{
$upload_filesize = $stats['size'] - $upload_position;
}
}
}
else
{
$upload_position = 0;
$upload_filesize = isset($opt['headers']['Content-Length']) ? $opt['headers']['Content-Length'] : filesize($opt['fileUpload']);
}

if ($upload_position === false || !isset($upload_filesize) || $upload_filesize === false || $upload_filesize < 0)
{
throw new S3_Exception('The size of `fileUpload` cannot be determined in ' . __FUNCTION__ . '().');
}

// Handle part size
Expand All @@ -3587,8 +3617,6 @@ public function create_mpu_object($bucket, $filename, $opt = null)
$opt['partSize'] = 52428800; // 50 MB
}

$upload_filesize = filesize($opt['fileUpload']);

// If the upload size is smaller than the piece size, failover to create_object().
if ($upload_filesize < $opt['partSize'] && !isset($opt['uploadId']))
{
Expand Down Expand Up @@ -3633,7 +3661,7 @@ public function create_mpu_object($bucket, $filename, $opt = null)
'expect' => '100-continue',
'fileUpload' => $opt['fileUpload'],
'partNumber' => ($i + 1),
'seekTo' => (integer) $piece['seekTo'],
'seekTo' => $upload_position + (integer) $piece['seekTo'],
'length' => (integer) $piece['length'],
));
}
Expand Down

0 comments on commit 340f030

Please sign in to comment.