Skip to content

Commit a8ac2dc

Browse files
author
lewzylu
committed
update TestResume
1 parent 5d0ff51 commit a8ac2dc

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/Qcloud/Cos/Client.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public function resumeUpload($bucket, $key, $body, $uploadId, $options = array()
179179
$multipartUpload = new MultipartUpload($this, $body, array(
180180
'Bucket' => $bucket,
181181
'Key' => $key,
182+
'UploadId' => $uploadId,
182183
) + $options);
183184

184185
$rt = $multipartUpload->resumeUploading();

src/Qcloud/Cos/MultipartUpload.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ public function resumeUploading() {
7171
'Bucket'=>$this->options['Bucket'],
7272
'Key'=>$this->options['Key']));
7373
$parts = array();
74-
$offset = $this->partSize;
7574
if (count($rt['Parts']) > 0) {
7675
foreach ($rt['Parts'] as $part) {
7776
$parts[$part['PartNumber'] - 1] = array('PartNumber' => $part['PartNumber'], 'ETag' => $part['ETag']);
7877
}
7978
}
80-
for ($partNumber = 1;;++$partNumber,$offset+=$body->getSize()) {
79+
for ($partNumber = 1;;++$partNumber) {
8180
if ($this->body->eof()) {
8281
break;
8382
}
@@ -88,7 +87,6 @@ public function resumeUploading() {
8887
if (md5($body) != substr($parts[$partNumber-1]['ETag'], 1, -1)){
8988
throw new CosException("ETag check inconsistency");
9089
}
91-
$body->setOffset($offset);
9290
continue;
9391
}
9492

src/Qcloud/Cos/Tests/Test.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class COSTest extends \PHPUnit_Framework_TestCase
1010
private $cosClient;
1111
private $bucket;
1212
private $region;
13-
private $message;
14-
private $ass;
1513
protected function setUp()
1614
{
1715
$this->bucket = getenv('COS_BUCKET');
@@ -1033,6 +1031,38 @@ public function testUploadLargeObject() {
10331031
}
10341032
}
10351033

1034+
/*
1035+
* 断点重传
1036+
* 200
1037+
*/
1038+
public function testResumeUpload() {
1039+
try {
1040+
$key = '你好.txt';
1041+
$body = $this->generateRandomString(3*1024*1024+1023);
1042+
$partSize = 1024 * 1024 + 1;
1043+
$md5 = base64_encode(md5($body, true));
1044+
$rt = $this->cosClient->CreateMultipartUpload(['Bucket' => $this->bucket,
1045+
'Key' => $key]);
1046+
$uploadId = $rt['UploadId'];
1047+
$this->cosClient->uploadPart(['Bucket' => $this->bucket,
1048+
'Key' => $key,
1049+
'Body' => substr($body, 0, $partSize),
1050+
'UploadId' => $uploadId,
1051+
'PartNumber' => 1]);
1052+
$this->cosClient->resumeUpload($bucket=$this->bucket,
1053+
$key=$key,
1054+
$body=$body,
1055+
$uploadId=$uploadId,
1056+
$options=['PartSize'=>$partSize]);
1057+
$rt = $this->cosClient->getObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
1058+
$download_md5 = base64_encode(md5($rt['Body'], true));
1059+
$this->assertEquals($md5, $download_md5);
1060+
} catch (ServiceResponseException $e) {
1061+
print $e;
1062+
$this->assertFalse(TRUE);
1063+
}
1064+
}
1065+
10361066
/*
10371067
* 下载文件
10381068
* 200

0 commit comments

Comments
 (0)