Skip to content

Commit d79d0d2

Browse files
committed
Merge pull request #98 from qiniu/develop
Release v6.1.2
2 parents 0ae9259 + 853af84 commit d79d0d2

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## CHANGE LOG
22

3+
### v6.1.2
4+
5+
2014-2-10 [#98](https://github.com/qiniu/java-sdk/pull/98)
6+
7+
- Add transform and fopTimeout Put Policy
8+
39
### v6.1.0
410

511
2014-1-13 [#93](https://github.com/qiniu/java-sdk/pull/93)

src/main/java/com/qiniu/api/rs/PutPolicy.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ public class PutPolicy {
4747

4848
public long deadline;
4949

50+
/**
51+
*
52+
* 对文件先进行一次变换操作(比如将音频统一转为某种码率的mp3)再进行存储。
53+
* transform的值就是一个fop指令,比如 "avthumb/mp3"。其含义是对上传的文件
54+
* 执行这个 fop 指令,然后把结果保存到七牛。最后保存的是经过处理过的文件,
55+
* 而不是用户上传的原始文件。
56+
*
57+
**/
58+
public String transform;
59+
60+
/**
61+
*
62+
* 单位: 秒
63+
* 文件变换操作执行的超时时间(单位:秒),上传和转码操作是同步进行的,
64+
* 先上传后转码,这个时间只是转码所需时间,不包括上传文件所需时间。
65+
* 这个值太小可能会导致误判(最终存储成功了但客户端得到超时的错误),
66+
* 但太大可能会导致服务端将其判断为低优先级任务。建议取一个相对准确的
67+
* 时间估计值*N(N不要超过5)。
68+
*
69+
**/
70+
public long fopTimeout;
71+
5072
public PutPolicy(String scope) {
5173
this.scope = scope;
5274
}
@@ -91,6 +113,12 @@ public String marshal() throws JSONException {
91113
if (this.persistentOps != null && this.persistentOps.length() > 0) {
92114
stringer.key("persistentOps").value(this.persistentOps);
93115
}
116+
if (this.transform != null && this.transform.length() > 0) {
117+
stringer.key("transform").value(this.transform);
118+
}
119+
if (this.fopTimeout > 0) {
120+
stringer.key("fopTimeout").value(this.fopTimeout);
121+
}
94122
stringer.key("deadline").value(this.deadline);
95123
stringer.endObject();
96124

src/test/java/com/qiniu/testing/IOTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ public void tearDown() {
8989
assertTrue(!sr.ok());
9090
}
9191
}
92-
}
92+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.qiniu.testing;
2+
3+
import java.io.*;
4+
5+
import junit.framework.TestCase;
6+
7+
import com.qiniu.api.auth.digest.Mac;
8+
import com.qiniu.api.config.Config;
9+
import com.qiniu.api.io.IoApi;
10+
import com.qiniu.api.io.PutExtra;
11+
import com.qiniu.api.io.PutRet;
12+
import com.qiniu.api.net.CallRet;
13+
import com.qiniu.api.rs.Entry;
14+
import com.qiniu.api.rs.PutPolicy;
15+
import com.qiniu.api.rs.RSClient;
16+
17+
public class TransformTest extends TestCase {
18+
19+
// because all the testcase concurrently executes
20+
// so the key should be different.
21+
public final String key = "IOTest-key";
22+
23+
public final String expectedHash = "FivxSqsM1SyWCnYeIGPUqZM5LL4b";
24+
25+
public String bucketName;
26+
27+
public Mac mac;
28+
@Override
29+
public void setUp() {
30+
Config.ACCESS_KEY = System.getenv("QINIU_ACCESS_KEY");
31+
Config.SECRET_KEY = System.getenv("QINIU_SECRET_KEY");
32+
Config.RS_HOST = System.getenv("QINIU_RS_HOST");
33+
bucketName = System.getenv("QINIU_TEST_BUCKET");
34+
35+
assertNotNull(Config.ACCESS_KEY);
36+
assertNotNull(Config.SECRET_KEY);
37+
assertNotNull(Config.RS_HOST);
38+
assertNotNull(bucketName);
39+
mac = new Mac(Config.ACCESS_KEY, Config.SECRET_KEY);
40+
}
41+
42+
public void testPutTransform() throws Exception {
43+
PutPolicy putPolicy = new PutPolicy(bucketName);
44+
putPolicy.transform = "imageView/2/w/100/h/100";
45+
putPolicy.fopTimeout = 10;
46+
47+
String uptoken = putPolicy.token(mac);
48+
String dir = System.getProperty("user.dir");
49+
String localFile = dir + "/testdata/" + "logo.png";
50+
51+
PutExtra extra = new PutExtra();
52+
53+
PutRet ret = IoApi.putFile(uptoken, key, localFile, extra);
54+
assertTrue(ret.ok());
55+
}
56+
57+
@Override
58+
public void tearDown() {
59+
// delete the metadata from rs
60+
// confirms it exists.
61+
{
62+
RSClient rs = new RSClient(mac);
63+
Entry sr = rs.stat(bucketName, key);
64+
System.out.println(sr.getHash());
65+
assertTrue(sr.ok());
66+
assertTrue(expectedHash.equals(sr.getHash()));
67+
}
68+
69+
// deletes it from rs
70+
{
71+
RSClient rs = new RSClient(mac);
72+
CallRet cr = rs.delete(bucketName, key);
73+
assertTrue(cr.ok());
74+
}
75+
76+
// confirms that it's deleted
77+
{
78+
RSClient rs = new RSClient(mac);
79+
Entry sr = rs.stat(bucketName, key);
80+
assertTrue(!sr.ok());
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)