Skip to content

Commit c11dbc4

Browse files
committed
putPolicy
1 parent 23b920e commit c11dbc4

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

qiniu/rs.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ function Qiniu_RS_MakeBaseUrl($domain, $key) // => $baseUrl
4141

4242
class Qiniu_RS_PutPolicy
4343
{
44-
public $Scope;
44+
public $Scope; //必填
45+
public $Expires; //默认为3600s
4546
public $CallbackUrl;
4647
public $CallbackBody;
4748
public $ReturnUrl;
4849
public $ReturnBody;
4950
public $AsyncOps;
5051
public $EndUser;
51-
public $Expires;
52+
public $InsertOnly; //若非0,则任何情况下无法覆盖上传
53+
public $DetectMime; //若非0,则服务端根据内容自动确定MimeType
54+
public $FsizeLimit;
55+
public $SaveKey;
5256
public $PersistentOps;
5357
public $PersistentNotifyUrl;
5458

@@ -84,6 +88,18 @@ public function Token($mac) // => $token
8488
if (!empty($this->EndUser)) {
8589
$policy['endUser'] = $this->EndUser;
8690
}
91+
if (!empty($this->InsertOnly)) {
92+
$policy['exclusive'] = $this->InsertOnly;
93+
}
94+
if (!empty($this->DetectMime)) {
95+
$policy['detectMime'] = $this->DetectMime;
96+
}
97+
if (!empty($this->FsizeLimit)) {
98+
$policy['fsizeLimit'] = $this->FsizeLimit;
99+
}
100+
if (!empty($this->SaveKey)) {
101+
$policy['saveKey'] = $this->SaveKey;
102+
}
87103
if (!empty($this->PersistentOps)) {
88104
$policy['persistentOps'] = $this->PersistentOps;
89105
}

tests/IoTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,19 @@ public function testPut()
5555
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
5656
$this->assertNull($err);
5757
}
58+
59+
public function testPut_sizelimit()
60+
{
61+
$key = 'testPut_sizelimit' . getTid();
62+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
63+
64+
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
65+
$putPolicy->FsizeLimit = 1;
66+
$upToken = $putPolicy->Token(null);
67+
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
68+
$this->assertNull($ret);
69+
$this->assertEquals($err->Err, 'exceed FsizeLimit');
70+
var_dump($ret);
71+
}
5872
}
5973

0 commit comments

Comments
 (0)