我们正尝试通过Multipart File Upload Process上传文件。通过使用下面给出的代码:
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.完成分段上传。
$result = $s3->completeMultipartUpload(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'Parts' => $parts,
));
$url = $result['Location'];
fclose($file);
通过使用此代码,文件将转换为Multipart但不可用于上载文件。它通过print_r显示这种类型的错误:
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[ServerSideEncryption] =>
[ETag] => "fcfc6838dfrtefr87b27b642e7d63021"
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[RequestId] => 4RTYPEFE054567369BD46D
)
)
上传/ tmp / phplA534j的第2部分。
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[ServerSideEncryption] =>
[ETag] => "d41d8uytrf67fdfrf00b204e9800998ecf8427e"
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[RequestId] => YTYPO67167874586EF802536C
)
)
上传/ tmp / phplA534j的第3部分。
你能帮帮我吗?
答案 0 :(得分:1)
两件事。首先,您可以使用SourceFile
代替Body
:
$result = $s3->uploadPart(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'SourceFile' => 'Path/To/Your/File.ext')
));
其次,这不是完成上传的正确方法:
$result = $s3->completeMultipartUpload(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'MultipartUpload' =>array('Parts'=> $parts),
));