Skip to content

Commit c3632bb

Browse files
committed
Merge pull request #66 from dtynn/feature/mimeLimit
Feature/mime limit
2 parents 91918a4 + 25452c0 commit c3632bb

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## CHANGE LOG
22

3+
### v6.1.8
4+
5+
2014-3-31 issues [#66](https://github.com/qiniu/php-sdk/pull/66)
6+
7+
- 上传策略[支持mimeLimit字段](http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html#put-policy-mime-limit),用于限定上传文件的mimeType。
8+
39
### v6.1.7
410

511
2014-2-19 issues [#64](https://github.com/qiniu/php-sdk/pull/64)

docs/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ SDK源码地址:<https://github.com/qiniu/php-sdk/tags>
253253
public $Expires; // 可选。默认是 3600 秒
254254
public $PersistentOps; // 可选。
255255
public $PersistentNotifyUrl; // 如果设置了PersistentOps,必须同时设置此项。
256+
public $InsertOnly; // 可选。如果设置为非0值,则无论scope设置为何种形式,都只能以`新增`方式上传,不能覆盖。
257+
public $DetectMime; // 可选。如果设为非0值,则忽略上传端传递的文件MimeType信息,使用七牛服务器侦测内容后的判断结果。
258+
public $FsizeLimit; // 可选。int类型,超过限制大小的上传内容会被判为上传失败,返回413状态码。
259+
public $SaveKey; // 可选。自定义资源名格式。
260+
public $Transform; // 可选。指定资源经过怎样的处理后再保存。
261+
public $FopTimeout; // 可选。int类型,指定transform的超时时间,如果文件处理超过此值,则认为上传失败。
262+
public $MimeLimit; // 可选。限定上传的文件类型。
256263
}
257264

258265
* `scope` 限定客户端的权限。如果 `scope` 是 bucket,则客户端只能新增文件到指定的 bucket,不能修改文件。如果 `scope` 为 bucket:key,则客户端可以修改指定的文件。**注意: key必须采用utf8编码,如使用非utf8编码访问七牛云存储将反馈错误**

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)