Skip to content

Commit dbf237f

Browse files
committed
Merge pull request #52 from qiniu/develop
Release v6.1.4
2 parents a5e7634 + 3428988 commit dbf237f

File tree

5 files changed

+167
-3
lines changed

5 files changed

+167
-3
lines changed

CHANGELOG.md

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

3+
### v6.1.4
4+
5+
2013-10-25 issues [#52](https://github.com/qiniu/php-sdk/pull/52)
6+
7+
- PutPolicy: 增加 saveKey、persistentOps/persistentNotifyUrl、fsizeLimit 等支持
8+
9+
310
### v6.1.3
411

512
2013-10-09 issues [#50](https://github.com/qiniu/php-sdk/pull/50)
@@ -8,6 +15,7 @@
815
- 修订文档
916
- 消除测试用例并发问题
1017

18+
1119
### v6.1.2
1220

1321
2013-09-24 issue [#40](https://github.com/qiniu/php-sdk/pull/40)

docs/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,18 @@ SDK源码地址:<https://github.com/qiniu/php-sdk/tags>
250250
public $AsyncOps; // 可选
251251
public $EndUser; // 可选
252252
public $Expires; // 可选。默认是 3600 秒
253+
public $PersistentOps; // 可选。
254+
public $PersistentNotifyUrl; // 如果设置了PersistentOps,必须同时设置此项。
253255
}
254256

255257
* `scope` 限定客户端的权限。如果 `scope` 是 bucket,则客户端只能新增文件到指定的 bucket,不能修改文件。如果 `scope` 为 bucket:key,则客户端可以修改指定的文件。**注意: key必须采用utf8编码,如使用非utf8编码访问七牛云存储将反馈错误**
256258
* `callbackUrl` 设定业务服务器的回调地址,这样业务服务器才能感知到上传行为的发生。
257259
* `callbackBody` 设定业务服务器的回调信息。文件上传成功后,七牛向业务服务器的callbackUrl发送的POST请求携带的数据。支持 [魔法变量](http://docs.qiniu.com/api/put.html#MagicVariables)[自定义变量](http://docs.qiniu.com/api/put.html#xVariables)
258260
* `returnUrl` 设置用于浏览器端文件上传成功后,浏览器执行301跳转的URL,一般为 HTML Form 上传时使用。文件上传成功后浏览器会自动跳转到 `returnUrl?upload_ret=returnBody`
259261
* `returnBody` 可调整返回给客户端的数据包,支持 [魔法变量](http://docs.qiniu.com/api/put.html#MagicVariables)[自定义变量](http://docs.qiniu.com/api/put.html#xVariables)`returnBody` 只在没有 `callbackUrl` 时有效(否则直接返回 `callbackUrl` 返回的结果)。不同情形下默认返回的 `returnBody` 并不相同。在一般情况下返回的是文件内容的 `hash`,也就是下载该文件时的 `etag`;但指定 `returnUrl` 时默认的 `returnBody` 会带上更多的信息。
260-
* `asyncOps` 可指定上传完成后,需要自动执行哪些数据处理。这是因为有些数据处理操作(比如音视频转码)比较慢,如果不进行预转可能第一次访问的时候效果不理想,预转可以很大程度改善这一点。
262+
* `asyncOps` 可指定上传完成后,需要自动执行哪些数据处理。这是因为有些数据处理操作(比如音视频转码)比较慢,如果不进行预转可能第一次访问的时候效果不理想,预转可以很大程度改善这一点。
263+
* `persistentOps` 可指定音视频文件上传完成后,需要进行的转码持久化操作。asyncOps的处理结果保存在缓存当中,有可能失效。而persistentOps的处理结果以文件形式保存在bucket中,体验更佳。[数据处理(持久化)](http://docs.qiniu.com/api/persistent-ops.html)
264+
* `persistentNotifyUrl` 音视频转码持久化完成后,七牛的服务器会向用户发送处理结果通知。这里指定的url就是用于接收通知的接口。设置了`persistentOps`,则需要同时设置此字段。
261265

262266
关于上传策略更完整的说明,请参考 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken)
263267

qiniu/rs.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ 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;
56+
public $PersistentOps;
57+
public $PersistentNotifyUrl;
5258

5359
public function __construct($scope)
5460
{
@@ -82,6 +88,24 @@ public function Token($mac) // => $token
8288
if (!empty($this->EndUser)) {
8389
$policy['endUser'] = $this->EndUser;
8490
}
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+
}
103+
if (!empty($this->PersistentOps)) {
104+
$policy['persistentOps'] = $this->PersistentOps;
105+
}
106+
if (!empty($this->PersistentNotifyUrl)) {
107+
$policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl;
108+
}
85109

86110
$b = json_encode($policy);
87111
return Qiniu_SignWithData($mac, $b);

tests/IoTest.php

+63
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,68 @@ 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($err);
71+
}
72+
73+
public function testPut_mime_save()
74+
{
75+
$key = 'testPut_mime_save' . getTid();
76+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
77+
78+
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
79+
$putPolicy->DetectMime = 1;
80+
$putPolicy->SaveKey = $key;
81+
$upToken = $putPolicy->Token(null);
82+
$putExtra = new Qiniu_PutExtra();
83+
$putExtra->MimeType = 'image/jpg';
84+
list($ret, $err) = Qiniu_PutFile($upToken, null, __file__, $putExtra);
85+
$this->assertNull($err);
86+
87+
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
88+
$this->assertNull($err);
89+
$this->assertEquals($ret['mimeType'], 'application/x-httpd-php');
90+
var_dump($ret);
91+
92+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
93+
$this->assertNull($err);
94+
}
95+
96+
public function testPut_exclusive()
97+
{
98+
$key = 'testPut_exclusive' . getTid();
99+
$scope = $this->bucket . ':' . $key;
100+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
101+
102+
$putPolicy = new Qiniu_RS_PutPolicy($scope);
103+
$putPolicy->InsertOnly = 1;
104+
$upToken = $putPolicy->Token(null);
105+
106+
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
107+
$this->assertNull($err);
108+
list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null);
109+
$this->assertNull($ret);
110+
$this->assertEquals($err->Err, 'file exists');
111+
var_dump($err);
112+
113+
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
114+
$this->assertNull($err);
115+
$this->assertEquals($ret['mimeType'], 'application/octet-stream');
116+
var_dump($ret);
117+
118+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
119+
$this->assertNull($err);
120+
}
58121
}
59122

tests/PersistentTest.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
require_once("bootstrap.php");
4+
5+
class PersistentTest extends PHPUnit_Framework_TestCase
6+
{
7+
public $bucket;
8+
public $client;
9+
10+
public function setUp()
11+
{
12+
initKeys();
13+
$this->client = new Qiniu_MacHttpClient(null);
14+
$this->bucket = getenv("QINIU_BUCKET_NAME");
15+
}
16+
17+
public function testPutFileWithPersistentOps()
18+
{
19+
$key = 'testPutFileWithPersistentOps' . getTid();
20+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
21+
22+
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
23+
$putPolicy->PersistentOps = 'avthumb/mp3';
24+
$putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
25+
$upToken = $putPolicy->Token(null);
26+
$putExtra = new Qiniu_PutExtra();
27+
$putExtra->CheckCrc = 1;
28+
list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, $putExtra);
29+
$this->assertNull($err);
30+
$this->assertArrayHasKey('hash', $ret);
31+
$this->assertArrayHasKey('persistentId', $ret);
32+
var_dump($ret);
33+
34+
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
35+
$this->assertNull($err);
36+
var_dump($ret);
37+
38+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
39+
$this->assertNull($err);
40+
}
41+
42+
public function testPutWithPersistentOps()
43+
{
44+
$key = 'testPutWithPersistentOps' . getTid();
45+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
46+
47+
$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
48+
$putPolicy->PersistentOps = 'avthumb/mp3';
49+
$putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
50+
$upToken = $putPolicy->Token(null);
51+
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
52+
$this->assertNull($err);
53+
$this->assertArrayHasKey('hash', $ret);
54+
$this->assertArrayHasKey('persistentId', $ret);
55+
var_dump($ret);
56+
57+
list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
58+
$this->assertNull($err);
59+
var_dump($ret);
60+
61+
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
62+
$this->assertNull($err);
63+
}
64+
}
65+

0 commit comments

Comments
 (0)