Skip to content

Commit

Permalink
Merge pull request #68 from qiniu/develop
Browse files Browse the repository at this point in the history
Release 6.1.8
  • Loading branch information
longbai committed Apr 5, 2014
2 parents d1c0814 + fff5a5d commit 8683816
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 3 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ before_script:
- export QINIU_KEY_NAME="file_name"
script:
- cd tests; phpunit .

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## CHANGE LOG

### v6.1.8

2014-4-6 issues [#68](https://github.com/qiniu/php-sdk/pull/68)

- [#66]上传策略[支持mimeLimit字段](http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html#put-policy-mime-limit),用于限定上传文件的mimeType。
- [#67] 新增接口的调用范例

### v6.1.7

2014-2-19 issues [#64](https://github.com/qiniu/php-sdk/pull/64)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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


## 下载
Expand Down Expand Up @@ -34,7 +34,7 @@

## 许可证

Copyright (c) 2012 qiniu.com
Copyright (c) 2012-2014 qiniu.com

基于 MIT 协议发布:

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

* `scope` 限定客户端的权限。如果 `scope` 是 bucket,则客户端只能新增文件到指定的 bucket,不能修改文件。如果 `scope` 为 bucket:key,则客户端可以修改指定的文件。**注意: key必须采用utf8编码,如使用非utf8编码访问七牛云存储将反馈错误**
Expand Down
32 changes: 32 additions & 0 deletions docs/gist/fetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

require_once("../../qiniu/http.php");
require_once("../../qiniu/auth_digest.php");
require_once("../../qiniu/utils.php");

$accessKey = "";
$secretKey = "";
$targetUrl = "";

$destBucket = "";
$destKey = "";

$encodedUrl = Qiniu_Encode($targetUrl);

$destEntry = "$destBucket:$destKey";
$encodedEntry = Qiniu_Encode($destEntry);

$apiHost = "http://iovip.qbox.me";
$apiPath = "/fetch/$encodedUrl/to/$encodedEntry";
$requestBody = "";

$mac = new Qiniu_Mac($accessKey, $secretKey);
$client = new Qiniu_MacHttpClient($mac);

list($ret, $err) = Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
if ($err !== null) {
echo "failed\n";
var_dump($err);
} else {
echo "success\n";
}
39 changes: 39 additions & 0 deletions docs/gist/pfop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

require_once("../../qiniu/http.php");
require_once("../../qiniu/auth_digest.php");
require_once("../../qiniu/utils.php");

$accessKey = "";
$secretKey = "";

$bucket = "";
$key = "";
$fops = "";
$notifyURL = "";
$force = 0;


$encodedBucket = urlencode($bucket);
$encodedKey = urlencode($key);
$encodedFops = urlencode($fops);
$encodedNotifyURL = urlencode($notifyURL);

$apiHost = "http://api.qiniu.com";
$apiPath = "/pfop/";
$requestBody = "bucket=$encodedBucket&key=$encodedKey&fops=$encodedFops&notifyURL=$encodedNotifyURL";
if ($force !== 0) {
$requestBody .= "&force=1";
}

$mac = new Qiniu_Mac($accessKey, $secretKey);
$client = new Qiniu_MacHttpClient($mac);

list($ret, $err) = Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
if ($err !== null) {
echo "failed\n";
var_dump($err);
} else {
echo "success\n";
var_dump($ret);
}
29 changes: 29 additions & 0 deletions docs/gist/prefetch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require_once("../../qiniu/http.php");
require_once("../../qiniu/auth_digest.php");
require_once("../../qiniu/utils.php");

$accessKey = "";
$secretKey = "";

$bucket = "";
$key = "";

$entry = "$bucket:$key";
$encodedEntry = Qiniu_Encode($entry);

$apiHost = "http://iovip.qbox.me";
$apiPath = "/prefetch/$encodedEntry";
$requestBody = "";

$mac = new Qiniu_Mac($accessKey, $secretKey);
$client = new Qiniu_MacHttpClient($mac);

list($ret, $err) = Qiniu_Client_CallWithForm($client, $apiHost . $apiPath, $requestBody);
if ($err !== null) {
echo "failed\n";
var_dump($err);
} else {
echo "success\n";
}
17 changes: 17 additions & 0 deletions qiniu/auth_digest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ public function SignRequest($req, $incbody) // => ($token, $error)
}
return $this->Sign($data);
}

public function VerifyCallback($auth, $url, $body) // ==> bool
{
$url = parse_url($url);
$data = '';
if (isset($url['path'])) {
$data = $url['path'];
}
if (isset($url['query'])) {
$data .= '?' . $url['query'];
}
$data .= "\n";

$data .= $body;
$token = 'QBox ' . $this->Sign($data);
return $auth === $token;
}
}

function Qiniu_SetKeys($accessKey, $secretKey)
Expand Down
5 changes: 5 additions & 0 deletions qiniu/rs.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Qiniu_RS_PutPolicy
public $PersistentNotifyUrl;
public $Transform;
public $FopTimeout;
public $MimeLimit;

public function __construct($scope)
{
Expand Down Expand Up @@ -114,6 +115,10 @@ public function Token($mac) // => $token
if (!empty($this->FopTimeout)) {
$policy['fopTimeout'] = $this->FopTimeout;
}
if (!empty($this->MimeLimit)) {
$policy['mimeLimit'] = $this->MimeLimit;
}


$b = json_encode($policy);
return Qiniu_SignWithData($mac, $b);
Expand Down
12 changes: 12 additions & 0 deletions tests/AuthDigestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class AuthDigestTest extends PHPUnit_Framework_TestCase
{

public function testEncode()
{
$cases = array(
Expand All @@ -16,6 +17,17 @@ public function testEncode()
}
}

public function testVerifyCallback()
{
initKeys();
$mac1 = Qiniu_RequireMac(null);
$auth = 'QBox Vhiv6a22kVN_zhtetbPNeG9sY3JUL1HG597EmBwQ:JrRyg9So6DNrNDY5qj1sygt0SmQ=';
$url = 'http://rs.qbox.me/batch';
$body = 'op=/delete/cGhwc2RrOnRlc3RPcDI=&op=/delete/cGhwc2RrOnRlc3RPcDM=&op=/delete/cGhwc2RrOnRlc3RPcDQ=';
$pass = $mac1->VerifyCallback($auth, $url, $body);
$this->assertTrue($pass);
}

/* public function testSetKeys()
{
$mac1 = Qiniu_RequireMac(null);
Expand Down
14 changes: 14 additions & 0 deletions tests/IoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,19 @@ public function testPut_transform() {
$this->assertEquals($ret["mimeType"], "image/png");
var_dump($ret);
}
public function testPut_mimeLimit() {
$key = 'testPut_mimeLimit' . getTid();
$scope = $this->bucket . ':' . $key;
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);

$putPolicy = new Qiniu_RS_PutPolicy($scope);
$putPolicy->MimeLimit = "image/*";
$upToken = $putPolicy->Token(null);

list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null);
$this->assertNull($ret);
$this->assertEquals($err->Err, "limited mimeType: this file type is forbidden to upload");
var_dump($err);
}
}

0 comments on commit 8683816

Please sign in to comment.