Skip to content

Wanglin/putpolicy #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions qiniu/rs.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ function Qiniu_RS_MakeBaseUrl($domain, $key) // => $baseUrl

class Qiniu_RS_PutPolicy
{
public $Scope;
public $Scope; //必填
public $Expires; //默认为3600s
public $CallbackUrl;
public $CallbackBody;
public $ReturnUrl;
public $ReturnBody;
public $AsyncOps;
public $EndUser;
public $Expires;
public $InsertOnly; //若非0,则任何情况下无法覆盖上传
public $DetectMime; //若非0,则服务端根据内容自动确定MimeType
public $FsizeLimit;
public $SaveKey;
public $PersistentOps;
public $PersistentNotifyUrl;

Expand Down Expand Up @@ -84,6 +88,18 @@ public function Token($mac) // => $token
if (!empty($this->EndUser)) {
$policy['endUser'] = $this->EndUser;
}
if (!empty($this->InsertOnly)) {
$policy['exclusive'] = $this->InsertOnly;
}
if (!empty($this->DetectMime)) {
$policy['detectMime'] = $this->DetectMime;
}
if (!empty($this->FsizeLimit)) {
$policy['fsizeLimit'] = $this->FsizeLimit;
}
if (!empty($this->SaveKey)) {
$policy['saveKey'] = $this->SaveKey;
}
if (!empty($this->PersistentOps)) {
$policy['persistentOps'] = $this->PersistentOps;
}
Expand Down
63 changes: 63 additions & 0 deletions tests/IoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,68 @@ public function testPut()
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}

public function testPut_sizelimit()
{
$key = 'testPut_sizelimit' . getTid();
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);

$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
$putPolicy->FsizeLimit = 1;
$upToken = $putPolicy->Token(null);
list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
$this->assertNull($ret);
$this->assertEquals($err->Err, 'exceed FsizeLimit');
var_dump($err);
}

public function testPut_mime_save()
{
$key = 'testPut_mime_save' . getTid();
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);

$putPolicy = new Qiniu_RS_PutPolicy($this->bucket);
$putPolicy->DetectMime = 1;
$putPolicy->SaveKey = $key;
$upToken = $putPolicy->Token(null);
$putExtra = new Qiniu_PutExtra();
$putExtra->MimeType = 'image/jpg';
list($ret, $err) = Qiniu_PutFile($upToken, null, __file__, $putExtra);
$this->assertNull($err);

list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
$this->assertNull($err);
$this->assertEquals($ret['mimeType'], 'application/x-httpd-php');
var_dump($ret);

$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}

public function testPut_exclusive()
{
$key = 'testPut_exclusive' . getTid();
$scope = $this->bucket . ':' . $key;
$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);

$putPolicy = new Qiniu_RS_PutPolicy($scope);
$putPolicy->InsertOnly = 1;
$upToken = $putPolicy->Token(null);

list($ret, $err) = Qiniu_Put($upToken, $key, "hello world!", null);
$this->assertNull($err);
list($ret, $err) = Qiniu_PutFile($upToken, $key, __file__, null);
$this->assertNull($ret);
$this->assertEquals($err->Err, 'file exists');
var_dump($err);

list($ret, $err) = Qiniu_RS_Stat($this->client, $this->bucket, $key);
$this->assertNull($err);
$this->assertEquals($ret['mimeType'], 'application/octet-stream');
var_dump($ret);

$err = Qiniu_RS_Delete($this->client, $this->bucket, $key);
$this->assertNull($err);
}
}