From 0eb541c7f64962a0d0eaf04df635f3c54fae913e Mon Sep 17 00:00:00 2001 From: dtynn Date: Sun, 29 Sep 2013 14:44:08 +0800 Subject: [PATCH 1/4] put policy add PersistentOps and PersistentNotifyUrl --- qiniu/rs.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/qiniu/rs.php b/qiniu/rs.php index 579c533e..0fa55b72 100644 --- a/qiniu/rs.php +++ b/qiniu/rs.php @@ -49,6 +49,8 @@ class Qiniu_RS_PutPolicy public $AsyncOps; public $EndUser; public $Expires; + public $PersistentOps; + public $PersistentNotifyUrl; public function __construct($scope) { @@ -82,6 +84,10 @@ public function Token($mac) // => $token if (!empty($this->EndUser)) { $policy['endUser'] = $this->EndUser; } + if (!empty($this->PersistentOps) && !empty($this->PersistentNotifyUrl)) { + $policy['persistentOps'] = $this->PersistentOps; + $policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl; + } $b = json_encode($policy); return Qiniu_SignWithData($mac, $b); From 34fc0e5f7774b39620c138931b726ee98867544b Mon Sep 17 00:00:00 2001 From: dtynn Date: Sun, 29 Sep 2013 15:29:59 +0800 Subject: [PATCH 2/4] unit test for persistentOps --- qiniu/rs.php | 12 ++++---- tests/PersistentTest.php | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 tests/PersistentTest.php diff --git a/qiniu/rs.php b/qiniu/rs.php index 0fa55b72..88013132 100644 --- a/qiniu/rs.php +++ b/qiniu/rs.php @@ -49,8 +49,8 @@ class Qiniu_RS_PutPolicy public $AsyncOps; public $EndUser; public $Expires; - public $PersistentOps; - public $PersistentNotifyUrl; + public $PersistentOps; + public $PersistentNotifyUrl; public function __construct($scope) { @@ -84,10 +84,10 @@ public function Token($mac) // => $token if (!empty($this->EndUser)) { $policy['endUser'] = $this->EndUser; } - if (!empty($this->PersistentOps) && !empty($this->PersistentNotifyUrl)) { - $policy['persistentOps'] = $this->PersistentOps; - $policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl; - } + if (!empty($this->PersistentOps) && !empty($this->PersistentNotifyUrl)) { + $policy['persistentOps'] = $this->PersistentOps; + $policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl; + } $b = json_encode($policy); return Qiniu_SignWithData($mac, $b); diff --git a/tests/PersistentTest.php b/tests/PersistentTest.php new file mode 100644 index 00000000..0f4e2beb --- /dev/null +++ b/tests/PersistentTest.php @@ -0,0 +1,65 @@ +client = new Qiniu_MacHttpClient(null); + $this->bucket = getenv("QINIU_BUCKET_NAME"); + } + + public function testPutFileWithPersistentOps() + { + $key = 'testPutFileWithPersistentOps' . getTid(); + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + + $putPolicy = new Qiniu_RS_PutPolicy($this->bucket); + $putPolicy->PersistentOps = 'avthumb/mp3'; + $putPolicy->PersistentNotifyUrl = 'http://someurl/abc'; + $upToken = $putPolicy->Token(null); + $putExtra = new Qiniu_PutExtra(); + $putExtra->CheckCrc = 1; + list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, $putExtra); + $this->assertNull($err); + $this->assertArrayHasKey('hash', $ret); + $this->assertArrayHasKey('persistentId', $ret); + var_dump($ret); + + list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key); + $this->assertNull($err); + var_dump($ret); + + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + $this->assertNull($err); + } + + public function testPutWithPersistentOps() + { + $key = 'testPutWithPersistentOps' . getTid(); + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + + $putPolicy = new Qiniu_RS_PutPolicy($this->bucket); + $putPolicy->PersistentOps = 'avthumb/mp3'; + $putPolicy->PersistentNotifyUrl = 'http://someurl/abc'; + $upToken = $putPolicy->Token(null); + list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null); + $this->assertNull($err); + $this->assertArrayHasKey('hash', $ret); + $this->assertArrayHasKey('persistentId', $ret); + var_dump($ret); + + list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key); + $this->assertNull($err); + var_dump($ret); + + $err = Qiniu_RS_Delete($this->client, $this->bucket, $key); + $this->assertNull($err); + } +} + From 2cd43f28a6d815f37c1e40788606253ab88d581f Mon Sep 17 00:00:00 2001 From: dtynn Date: Fri, 18 Oct 2013 11:48:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8C=81=E4=B9=85=E5=8C=96=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E7=9B=B8=E4=BA=92=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qiniu/rs.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/qiniu/rs.php b/qiniu/rs.php index 88013132..beb5031f 100644 --- a/qiniu/rs.php +++ b/qiniu/rs.php @@ -84,8 +84,10 @@ public function Token($mac) // => $token if (!empty($this->EndUser)) { $policy['endUser'] = $this->EndUser; } - if (!empty($this->PersistentOps) && !empty($this->PersistentNotifyUrl)) { + if (!empty($this->PersistentOps)) { $policy['persistentOps'] = $this->PersistentOps; + } + if (!empty($this->PersistentNotifyUrl)) { $policy['persistentNotifyUrl'] = $this->PersistentNotifyUrl; } From 1d5257f25444f7b64798b420b5bf81c4171fb0b6 Mon Sep 17 00:00:00 2001 From: dtynn Date: Tue, 22 Oct 2013 11:27:41 +0800 Subject: [PATCH 4/4] docs add persistentOps --- docs/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 5677d119..77dcaa4a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -250,6 +250,8 @@ SDK源码地址: public $AsyncOps; // 可选 public $EndUser; // 可选 public $Expires; // 可选。默认是 3600 秒 + public $PersistentOps; // 可选。 + public $PersistentNotifyUrl; // 如果设置了PersistentOps,必须同时设置此项。 } * `scope` 限定客户端的权限。如果 `scope` 是 bucket,则客户端只能新增文件到指定的 bucket,不能修改文件。如果 `scope` 为 bucket:key,则客户端可以修改指定的文件。 @@ -257,7 +259,9 @@ SDK源码地址: * `callbackBody` 设定业务服务器的回调信息。文件上传成功后,七牛向业务服务器的callbackUrl发送的POST请求携带的数据。支持 [魔法变量](http://docs.qiniu.com/api/put.html#MagicVariables) 和 [自定义变量](http://docs.qiniu.com/api/put.html#xVariables)。 * `returnUrl` 设置用于浏览器端文件上传成功后,浏览器执行301跳转的URL,一般为 HTML Form 上传时使用。文件上传成功后浏览器会自动跳转到 `returnUrl?upload_ret=returnBody`。 * `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` 会带上更多的信息。 -* `asyncOps` 可指定上传完成后,需要自动执行哪些数据处理。这是因为有些数据处理操作(比如音视频转码)比较慢,如果不进行预转可能第一次访问的时候效果不理想,预转可以很大程度改善这一点。 +* `asyncOps` 可指定上传完成后,需要自动执行哪些数据处理。这是因为有些数据处理操作(比如音视频转码)比较慢,如果不进行预转可能第一次访问的时候效果不理想,预转可以很大程度改善这一点。 +* `persistentOps` 可指定音视频文件上传完成后,需要进行的转码持久化操作。asyncOps的处理结果保存在缓存当中,有可能失效。而persistentOps的处理结果以文件形式保存在bucket中,体验更佳。[数据处理(持久化)](http://docs.qiniu.com/api/persistent-ops.html) +* `persistentNotifyUrl` 音视频转码持久化完成后,七牛的服务器会向用户发送处理结果通知。这里指定的url就是用于接收通知的接口。设置了`persistentOps`,则需要同时设置此字段。 关于上传策略更完整的说明,请参考 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken)。