Skip to content

Commit 25c74b9

Browse files
committed
mimeLimit
1 parent 91918a4 commit 25c74b9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

qiniu/rs.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Qiniu_RS_PutPolicy
5757
public $PersistentNotifyUrl;
5858
public $Transform;
5959
public $FopTimeout;
60+
public $MimeLimit;
6061

6162
public function __construct($scope)
6263
{
@@ -114,6 +115,10 @@ public function Token($mac) // => $token
114115
if (!empty($this->FopTimeout)) {
115116
$policy['fopTimeout'] = $this->FopTimeout;
116117
}
118+
if (!empty($this->MimeLimit)) {
119+
$policy['mimeLimit'] = $this->MimeLimit;
120+
}
121+
117122

118123
$b = json_encode($policy);
119124
return Qiniu_SignWithData($mac, $b);

tests/IoTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,19 @@ public function testPut_transform() {
169169
$this->assertEquals($ret["mimeType"], "image/png");
170170
var_dump($ret);
171171
}
172+
public function testPut_mimeLimit() {
173+
$key = 'testPut_mimeLimit' . getTid();
174+
$scope = $this->bucket . ':' . $key;
175+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
176+
177+
$putPolicy = new Qiniu_RS_PutPolicy($scope);
178+
$putPolicy->MimeLimit = "image/*";
179+
$upToken = $putPolicy->Token(null);
180+
181+
list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null);
182+
$this->assertNull($ret);
183+
$this->assertEquals($err->Err, "limited mimeType: this file type is forbidden to upload");
184+
var_dump($err);
185+
}
172186
}
173187

0 commit comments

Comments
 (0)