diff --git a/src/Qcloud/Cos/CosTransformer.php b/src/Qcloud/Cos/CosTransformer.php index e4338b9d..c4994a55 100644 --- a/src/Qcloud/Cos/CosTransformer.php +++ b/src/Qcloud/Cos/CosTransformer.php @@ -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."); diff --git a/src/Qcloud/Cos/Tests/Test.php b/src/Qcloud/Cos/Tests/Test.php index 53d14adb..19c9f645 100644 --- a/src/Qcloud/Cos/Tests/Test.php +++ b/src/Qcloud/Cos/Tests/Test.php @@ -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