Skip to content

Commit 0968ddf

Browse files
authored
Patch putobject fopen (#129)
* update Test * patch putObject with fopen * update
1 parent e15eb2e commit 0968ddf

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/Qcloud/Cos/CosTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public function uploadBodyTransformer(CommandInterface $command, $request, $body
8888
$body = fopen($source, 'rb');
8989
}
9090
// Prepare the body parameter and remove the source file parameter
91-
if (null !== $body) {
92-
return $request->withBody(Psr7\stream_for($body));
91+
if (null !== $body) {
92+
return $request;
9393
} else {
9494
throw new Exception\InvalidArgumentException(
9595
"You must specify a non-null value for the {$bodyParameter} or {$sourceParameter} parameters.");

src/Qcloud/Cos/Tests/Test.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,57 @@ public function testGetBucketLocationNonExisted()
867867
* TestObject
868868
**********************************/
869869

870+
/*
871+
* put object, 从本地上传文件
872+
* 200
873+
*/
874+
public function testPutObjectLocalObject() {
875+
try {
876+
$key = '你好.txt';
877+
$body = $this->generateRandomString(1024+1023);
878+
$md5 = base64_encode(md5($body, true));
879+
$local_test_key = "local_test_file";
880+
$f = fopen($local_test_key, "wb");
881+
fwrite($f, $body);
882+
fclose($f);
883+
$this->cosClient->putObject(['Bucket' => $this->bucket,
884+
'Key' => $key,
885+
'Body' => fopen($local_test_key, "rb")]);
886+
$rt = $this->cosClient->getObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
887+
$download_md5 = base64_encode(md5($rt['Body'], true));
888+
$this->assertEquals($md5, $download_md5);
889+
} catch (ServiceResponseException $e) {
890+
print $e;
891+
$this->assertFalse(TRUE);
892+
}
893+
}
894+
895+
/*
896+
* upload, 从本地上传
897+
* 200
898+
*/
899+
public function testUploadLocalObject() {
900+
try {
901+
$key = '你好.txt';
902+
$body = $this->generateRandomString(1024+1023);
903+
$md5 = base64_encode(md5($body, true));
904+
$local_test_key = "local_test_file";
905+
$f = fopen($local_test_key, "wb");
906+
fwrite($f, $body);
907+
fclose($f);
908+
$this->cosClient->upload($bucket=$this->bucket,
909+
$key=$key,
910+
$body=fopen($local_test_key, "rb"),
911+
$options=['PartSize'=>1024 * 1024 + 1]);
912+
$rt = $this->cosClient->getObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
913+
$download_md5 = base64_encode(md5($rt['Body'], true));
914+
$this->assertEquals($md5, $download_md5);
915+
} catch (ServiceResponseException $e) {
916+
print $e;
917+
$this->assertFalse(TRUE);
918+
}
919+
}
920+
870921
/*
871922
* put object,请求头部携带服务端加密参数
872923
* 200

0 commit comments

Comments
 (0)