diff --git a/qiniu/rs.php b/qiniu/rs.php index beb5031f..db79caa3 100644 --- a/qiniu/rs.php +++ b/qiniu/rs.php @@ -41,14 +41,18 @@ function Qiniu_RS_MakeBaseUrl($domain, $key) // => $baseUrl class Qiniu_RS_PutPolicy { - public $Scope; + public $Scope; //必填 + public $Expires; //默认为3600s public $CallbackUrl; public $CallbackBody; public $ReturnUrl; public $ReturnBody; public $AsyncOps; public $EndUser; - public $Expires; + public $InsertOnly; //若非0,则任何情况下无法覆盖上传 + public $DetectMime; //若非0,则服务端根据内容自动确定MimeType + public $FsizeLimit; + public $SaveKey; public $PersistentOps; public $PersistentNotifyUrl; @@ -84,6 +88,18 @@ public function Token($mac) // => $token if (!empty($this->EndUser)) { $policy['endUser'] = $this->EndUser; } + if (!empty($this->InsertOnly)) { + $policy['exclusive'] = $this->InsertOnly; + } + if (!empty($this->DetectMime)) { + $policy['detectMime'] = $this->DetectMime; + } + if (!empty($this->FsizeLimit)) { + $policy['fsizeLimit'] = $this->FsizeLimit; + } + if (!empty($this->SaveKey)) { + $policy['saveKey'] = $this->SaveKey; + } if (!empty($this->PersistentOps)) { $policy['persistentOps'] = $this->PersistentOps; } diff --git a/tests/IoTest.php b/tests/IoTest.php index 18f29065..16d04f71 100644 --- a/tests/IoTest.php +++ b/tests/IoTest.php @@ -55,5 +55,68 @@ public function testPut() $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); $this->assertNull($err); } + + public function testPut_sizelimit() + { + $key = 'testPut_sizelimit' . getTid(); + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + + $putPolicy = new Qiniu_RS_PutPolicy($this->bucket); + $putPolicy->FsizeLimit = 1; + $upToken = $putPolicy->Token(null); + list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null); + $this->assertNull($ret); + $this->assertEquals($err->Err, 'exceed FsizeLimit'); + var_dump($err); + } + + public function testPut_mime_save() + { + $key = 'testPut_mime_save' . getTid(); + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + + $putPolicy = new Qiniu_RS_PutPolicy($this->bucket); + $putPolicy->DetectMime = 1; + $putPolicy->SaveKey = $key; + $upToken = $putPolicy->Token(null); + $putExtra = new Qiniu_PutExtra(); + $putExtra->MimeType = 'image/jpg'; + list($ret, $err) = Qiniu_PutFile($upToken, null, __file__, $putExtra); + $this->assertNull($err); + + list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key); + $this->assertNull($err); + $this->assertEquals($ret['mimeType'], 'application/x-httpd-php'); + var_dump($ret); + + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + $this->assertNull($err); + } + + public function testPut_exclusive() + { + $key = 'testPut_exclusive' . getTid(); + $scope = $this->bucket . ':' . $key; + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + + $putPolicy = new Qiniu_RS_PutPolicy($scope); + $putPolicy->InsertOnly = 1; + $upToken = $putPolicy->Token(null); + + list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null); + $this->assertNull($err); + list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null); + $this->assertNull($ret); + $this->assertEquals($err->Err, 'file exists'); + var_dump($err); + + list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key); + $this->assertNull($err); + $this->assertEquals($ret['mimeType'], 'application/octet-stream'); + var_dump($ret); + + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + $this->assertNull($err); + } }