标准扩展接口
该接口可以根据 Upload ID 中止对应的 Multipart Upload。当一个 Multipart Upload 被中止后,就不能再使用这个 Upload ID 做任何操作,已经上传的 Part 数据也会被删除。
//UploadId从createMultipartUpload中获取
$bucket = '<your-bucket-name>';
$keyname = '<your-object-key>';
$uploadId = '<your-upload-id>';
$s3->abortMultipartUpload([
'Bucket' => $bucket,
'Key' => $keyname,
'UploadId' => $uploadId,
]);
您可以通过 listParts 接口根据 Upload ID 获取所有已经上传成功的分片。默认每次请求返回的分片数为1000。
$bucket = '<your-bucket-name>';
$keyname = '<your-object-key>';
$uploadId = '<your-upload-id>';
$result = $s3->listParts([
'Bucket' => $bucket,
'Key' => $keyname,
'UploadId' => $uploadId,
]);
print_r($result->toArray());
如果 list 大于1000,则可以使用 getPaginator 接口列举所有分片。列举所有分片示例代码如下:
$bucket = '<your-bucket-name>';
$keyname = '<your-object-key>';
$uploadId = '<your-upload-id>';
try {
$results = $s3->getPaginator('ListParts', [
'Bucket' => $bucket,
'Key' => $keyname,
'UploadId' => $uploadId,
]);
foreach ($results as $result) {
foreach ($result['Parts'] as $part) {
echo 'part number:' . $part['PartNumber'] . "\n";
echo 'ETag:' . $part['ETag'] . "\n";
echo 'size' . $part['Size'] . "\n";
}
}
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}
您可以通过 listMultipartUploads 接口列举分片上传事件,包括已经初始化的尚未Complete或者Abort的分片上传事件。默认情况下,每次list操作最多返回1000个分片上传事件。以下代码展示如何简单列举分片上传事件:
$bucket = '<your-bucket-name>';
// 获取当前的分片上传
$result = $s3->listMultipartUploads([
'Bucket' => $bucket
]);
var_dump($result);
如果 list 大于1000,则可以使用 getPaginator 接口列举所有分片上传事件。列举所有分片上传事件示例代码如下:
$bucket = '<your-bucket-name>';
try {
$results = $s3->getPaginator('ListMultipartUploads', [
'Bucket' => $bucket
]);
foreach ($results as $result) {
foreach ($result['Uploads'] as $upload) {
echo 'object key: ' . $upload['Key'] . "\n";
echo 'uploadId: ' . $upload['UploadId'] . "\n";
}
}
} catch (S3Exception $e) {
echo $e->getMessage() . "\n";
}