Skip to content

Commit

Permalink
Merge pull request #98 from qiniu/develop
Browse files Browse the repository at this point in the history
Release v6.1.2
  • Loading branch information
xushiwei committed Feb 10, 2014
2 parents 0ae9259 + 853af84 commit d79d0d2
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## CHANGE LOG

### v6.1.2

2014-2-10 [#98](https://github.com/qiniu/java-sdk/pull/98)

- Add transform and fopTimeout Put Policy

### v6.1.0

2014-1-13 [#93](https://github.com/qiniu/java-sdk/pull/93)
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/qiniu/api/rs/PutPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ public class PutPolicy {

public long deadline;

/**
*
* 对文件先进行一次变换操作(比如将音频统一转为某种码率的mp3)再进行存储。
* transform的值就是一个fop指令,比如 "avthumb/mp3"。其含义是对上传的文件
* 执行这个 fop 指令,然后把结果保存到七牛。最后保存的是经过处理过的文件,
* 而不是用户上传的原始文件。
*
**/
public String transform;

/**
*
* 单位: 秒
* 文件变换操作执行的超时时间(单位:秒),上传和转码操作是同步进行的,
* 先上传后转码,这个时间只是转码所需时间,不包括上传文件所需时间。
* 这个值太小可能会导致误判(最终存储成功了但客户端得到超时的错误),
* 但太大可能会导致服务端将其判断为低优先级任务。建议取一个相对准确的
* 时间估计值*N(N不要超过5)。
*
**/
public long fopTimeout;

public PutPolicy(String scope) {
this.scope = scope;
}
Expand Down Expand Up @@ -91,6 +113,12 @@ public String marshal() throws JSONException {
if (this.persistentOps != null && this.persistentOps.length() > 0) {
stringer.key("persistentOps").value(this.persistentOps);
}
if (this.transform != null && this.transform.length() > 0) {
stringer.key("transform").value(this.transform);
}
if (this.fopTimeout > 0) {
stringer.key("fopTimeout").value(this.fopTimeout);
}
stringer.key("deadline").value(this.deadline);
stringer.endObject();

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/qiniu/testing/IOTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public void tearDown() {
assertTrue(!sr.ok());
}
}
}
}
83 changes: 83 additions & 0 deletions src/test/java/com/qiniu/testing/TransformTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.qiniu.testing;

import java.io.*;

import junit.framework.TestCase;

import com.qiniu.api.auth.digest.Mac;
import com.qiniu.api.config.Config;
import com.qiniu.api.io.IoApi;
import com.qiniu.api.io.PutExtra;
import com.qiniu.api.io.PutRet;
import com.qiniu.api.net.CallRet;
import com.qiniu.api.rs.Entry;
import com.qiniu.api.rs.PutPolicy;
import com.qiniu.api.rs.RSClient;

public class TransformTest extends TestCase {

// because all the testcase concurrently executes
// so the key should be different.
public final String key = "IOTest-key";

public final String expectedHash = "FivxSqsM1SyWCnYeIGPUqZM5LL4b";

public String bucketName;

public Mac mac;
@Override
public void setUp() {
Config.ACCESS_KEY = System.getenv("QINIU_ACCESS_KEY");
Config.SECRET_KEY = System.getenv("QINIU_SECRET_KEY");
Config.RS_HOST = System.getenv("QINIU_RS_HOST");
bucketName = System.getenv("QINIU_TEST_BUCKET");

assertNotNull(Config.ACCESS_KEY);
assertNotNull(Config.SECRET_KEY);
assertNotNull(Config.RS_HOST);
assertNotNull(bucketName);
mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
}

public void testPutTransform() throws Exception {
PutPolicy putPolicy = new PutPolicy(bucketName);
putPolicy.transform = "imageView/2/w/100/h/100";
putPolicy.fopTimeout = 10;

String uptoken = putPolicy.token(mac);
String dir = System.getProperty("user.dir");
String localFile = dir + "/testdata/" + "logo.png";

PutExtra extra = new PutExtra();

PutRet ret = IoApi.putFile(uptoken, key, localFile, extra);
assertTrue(ret.ok());
}

@Override
public void tearDown() {
// delete the metadata from rs
// confirms it exists.
{
RSClient rs = new RSClient(mac);
Entry sr = rs.stat(bucketName, key);
System.out.println(sr.getHash());
assertTrue(sr.ok());
assertTrue(expectedHash.equals(sr.getHash()));
}

// deletes it from rs
{
RSClient rs = new RSClient(mac);
CallRet cr = rs.delete(bucketName, key);
assertTrue(cr.ok());
}

// confirms that it's deleted
{
RSClient rs = new RSClient(mac);
Entry sr = rs.stat(bucketName, key);
assertTrue(!sr.ok());
}
}
}

0 comments on commit d79d0d2

Please sign in to comment.