Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Qcloud/Cos/CosTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function uploadBodyTransformer(CommandInterface $command, $request, $body
$body = fopen($source, 'rb');
}
// Prepare the body parameter and remove the source file parameter
if (null !== $body) {
return $request->withBody(Psr7\stream_for($body));
if (null !== $body) {
return $request;
} else {
throw new Exception\InvalidArgumentException(
"You must specify a non-null value for the {$bodyParameter} or {$sourceParameter} parameters.");
Expand Down
51 changes: 51 additions & 0 deletions src/Qcloud/Cos/Tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,57 @@ public function testGetBucketLocationNonExisted()
* TestObject
**********************************/

/*
* put object, 从本地上传文件
* 200
*/
public function testPutObjectLocalObject() {
try {
$key = '你好.txt';
$body = $this->generateRandomString(1024+1023);
$md5 = base64_encode(md5($body, true));
$local_test_key = "local_test_file";
$f = fopen($local_test_key, "wb");
fwrite($f, $body);
fclose($f);
$this->cosClient->putObject(['Bucket' => $this->bucket,
'Key' => $key,
'Body' => fopen($local_test_key, "rb")]);
$rt = $this->cosClient->getObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
$download_md5 = base64_encode(md5($rt['Body'], true));
$this->assertEquals($md5, $download_md5);
} catch (ServiceResponseException $e) {
print $e;
$this->assertFalse(TRUE);
}
}

/*
* upload, 从本地上传
* 200
*/
public function testUploadLocalObject() {
try {
$key = '你好.txt';
$body = $this->generateRandomString(1024+1023);
$md5 = base64_encode(md5($body, true));
$local_test_key = "local_test_file";
$f = fopen($local_test_key, "wb");
fwrite($f, $body);
fclose($f);
$this->cosClient->upload($bucket=$this->bucket,
$key=$key,
$body=fopen($local_test_key, "rb"),
$options=['PartSize'=>1024 * 1024 + 1]);
$rt = $this->cosClient->getObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
$download_md5 = base64_encode(md5($rt['Body'], true));
$this->assertEquals($md5, $download_md5);
} catch (ServiceResponseException $e) {
print $e;
$this->assertFalse(TRUE);
}
}

/*
* put object,请求头部携带服务端加密参数
* 200
Expand Down