Reputation: 47
We are trying to upload file through Multipart File Upload Process. By using this given below code:
while (!feof($file)) {
$result = $s3->uploadPart(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'Body' => fread($file, filesize($filename))
));
$parts[] = array(
'PartNumber' => $partNumber++,
'ETag' => $result['ETag'],
);
}
// 4. Complete multipart upload.
$result = $s3->completeMultipartUpload(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'Parts' => $parts,
));
$url = $result['Location'];
fclose($file);
By using this code, file is converted into Multipart but unavailable to upload the file. It's showing this type of error through print_r:
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[ServerSideEncryption] =>
[ETag] => "fcfc6838dfrtefr87b27b642e7d63021"
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[RequestId] => 4RTYPEFE054567369BD46D
)
)
Uploading part 2 of /tmp/phplA534j.
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[ServerSideEncryption] =>
[ETag] => "d41d8uytrf67fdfrf00b204e9800998ecf8427e"
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[RequestId] => YTYPO67167874586EF802536C
)
)
Uploading part 3 of /tmp/phplA534j.
Can you please help me?
Upvotes: 3
Views: 125
Reputation: 11
Two things. First, you can use SourceFile
instead of Body
:
$result = $s3->uploadPart(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'SourceFile' => 'Path/To/Your/File.ext')
));
Second, That is not the correct way for completing your upload:
$result = $s3->completeMultipartUpload(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'MultipartUpload' =>array('Parts'=> $parts),
));
Upvotes: 1