Skip to content

Commit 8683816

Browse files
committed
Merge pull request #68 from qiniu/develop
Release 6.1.8
2 parents d1c0814 + fff5a5d commit 8683816

11 files changed

+164
-3
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ before_script:
1010
- export QINIU_KEY_NAME="file_name"
1111
script:
1212
- cd tests; phpunit .
13-

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## CHANGE LOG
22

3+
### v6.1.8
4+
5+
2014-4-6 issues [#68](https://github.com/qiniu/php-sdk/pull/68)
6+
7+
- [#66]上传策略[支持mimeLimit字段](http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html#put-policy-mime-limit),用于限定上传文件的mimeType。
8+
- [#67] 新增接口的调用范例
9+
310
### v6.1.7
411

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

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://api.travis-ci.org/qiniu/php-sdk.png?branch=master)](https://travis-ci.org/qiniu/php-sdk)
44

5-
[![Qiniu Logo](http://qiniutek.com/images/logo-2.png)](http://qiniu.com/)
5+
[![Qiniu Logo](http://qiniu-brand.qiniudn.com/5/logo-white-195x105.png)](http://www.qiniu.com/)
66

77

88
## 下载
@@ -34,7 +34,7 @@
3434

3535
## 许可证
3636

37-
Copyright (c) 2012 qiniu.com
37+
Copyright (c) 2012-2014 qiniu.com
3838

3939
基于 MIT 协议发布:
4040

docs/README.md

+7
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编码访问七牛云存储将反馈错误**

docs/gist/fetch.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
require_once("../../qiniu/http.php");
4+
require_once("../../qiniu/auth_digest.php");
5+
require_once("../../qiniu/utils.php");
6+
7+
$accessKey = "";
8+
$secretKey = "";
9+
$targetUrl = "";
10+
11+
$destBucket = "";
12+
$destKey = "";
13+
14+
$encodedUrl = Qiniu_Encode($targetUrl);
15+
16+
$destEntry = "$destBucket:$destKey";
17+
$encodedEntry = Qiniu_Encode($destEntry);
18+
19+
$apiHost = "http://iovip.qbox.me";
20+
$apiPath = "/fetch/$encodedUrl/to/$encodedEntry";
21+
$requestBody = "";
22+
23+
$mac = new Qiniu_Mac($accessKey, $secretKey);
24+
$client = new Qiniu_MacHttpClient($mac);
25+
26+
list($ret, $err) = Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
27+
if ($err !== null) {
28+
echo "failed\n";
29+
var_dump($err);
30+
} else {
31+
echo "success\n";
32+
}

docs/gist/pfop.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
require_once("../../qiniu/http.php");
4+
require_once("../../qiniu/auth_digest.php");
5+
require_once("../../qiniu/utils.php");
6+
7+
$accessKey = "";
8+
$secretKey = "";
9+
10+
$bucket = "";
11+
$key = "";
12+
$fops = "";
13+
$notifyURL = "";
14+
$force = 0;
15+
16+
17+
$encodedBucket = urlencode($bucket);
18+
$encodedKey = urlencode($key);
19+
$encodedFops = urlencode($fops);
20+
$encodedNotifyURL = urlencode($notifyURL);
21+
22+
$apiHost = "http://api.qiniu.com";
23+
$apiPath = "/pfop/";
24+
$requestBody = "bucket=$encodedBucket&key=$encodedKey&fops=$encodedFops&notifyURL=$encodedNotifyURL";
25+
if ($force !== 0) {
26+
$requestBody .= "&force=1";
27+
}
28+
29+
$mac = new Qiniu_Mac($accessKey, $secretKey);
30+
$client = new Qiniu_MacHttpClient($mac);
31+
32+
list($ret, $err) = Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
33+
if ($err !== null) {
34+
echo "failed\n";
35+
var_dump($err);
36+
} else {
37+
echo "success\n";
38+
var_dump($ret);
39+
}

docs/gist/prefetch.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
require_once("../../qiniu/http.php");
4+
require_once("../../qiniu/auth_digest.php");
5+
require_once("../../qiniu/utils.php");
6+
7+
$accessKey = "";
8+
$secretKey = "";
9+
10+
$bucket = "";
11+
$key = "";
12+
13+
$entry = "$bucket:$key";
14+
$encodedEntry = Qiniu_Encode($entry);
15+
16+
$apiHost = "http://iovip.qbox.me";
17+
$apiPath = "/prefetch/$encodedEntry";
18+
$requestBody = "";
19+
20+
$mac = new Qiniu_Mac($accessKey, $secretKey);
21+
$client = new Qiniu_MacHttpClient($mac);
22+
23+
list($ret, $err) = Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
24+
if ($err !== null) {
25+
echo "failed\n";
26+
var_dump($err);
27+
} else {
28+
echo "success\n";
29+
}

qiniu/auth_digest.php

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ public function SignRequest($req, $incbody) // => ($token, $error)
4646
}
4747
return $this->Sign($data);
4848
}
49+
50+
public function VerifyCallback($auth, $url, $body) // ==> bool
51+
{
52+
$url = parse_url($url);
53+
$data = '';
54+
if (isset($url['path'])) {
55+
$data = $url['path'];
56+
}
57+
if (isset($url['query'])) {
58+
$data .= '?' . $url['query'];
59+
}
60+
$data .= "\n";
61+
62+
$data .= $body;
63+
$token = 'QBox ' . $this->Sign($data);
64+
return $auth === $token;
65+
}
4966
}
5067

5168
function Qiniu_SetKeys($accessKey, $secretKey)

qiniu/rs.php

+5
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/AuthDigestTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class AuthDigestTest extends PHPUnit_Framework_TestCase
66
{
7+
78
public function testEncode()
89
{
910
$cases = array(
@@ -16,6 +17,17 @@ public function testEncode()
1617
}
1718
}
1819

20+
public function testVerifyCallback()
21+
{
22+
initKeys();
23+
$mac1 = Qiniu_RequireMac(null);
24+
$auth = 'QBox Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ:JrRyg9So6DNrNDY5qj1sygt0SmQ=';
25+
$url = 'http://rs.qbox.me/batch';
26+
$body = 'op=/delete/cGhwc2RrOnRlc3RPcDI=&op=/delete/cGhwc2RrOnRlc3RPcDM=&op=/delete/cGhwc2RrOnRlc3RPcDQ=';
27+
$pass = $mac1->VerifyCallback($auth, $url, $body);
28+
$this->assertTrue($pass);
29+
}
30+
1931
/* public function testSetKeys()
2032
{
2133
$mac1 = Qiniu_RequireMac(null);

tests/IoTest.php

+14
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)