File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
main/java/com/qiniu/api/rs
test/java/com/qiniu/testing Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,27 @@ public class PutPolicy {
47
47
48
48
public long deadline ;
49
49
50
+ /**
51
+ *
52
+ * 对文件先进行一次变换操作(比如将音频统一转为某种码率的mp3)再进行存储。
53
+ * transform的值就是一个fop指令,比如 "avthumb/mp3"。其含义是对上传的文件
54
+ * 执行这个 fop 指令,然后把结果保存到七牛。最后保存的是经过处理过的文件,
55
+ * 而不是用户上传的原始文件。
56
+ **/
57
+ public String transform ;
58
+
59
+ /**
60
+ *
61
+ * 单位: 秒
62
+ * 文件变换操作执行的超时时间(单位:秒),上传和转码操作是同步进行的,
63
+ * 先上传后转码,这个时间只是转码所需时间,不包括上传文件所需时间。
64
+ * 这个值太小可能会导致误判(最终存储成功了但客户端得到超时的错误),
65
+ * 但太大可能会导致服务端将其判断为低优先级任务。建议取一个相对准确的
66
+ * 时间估计值*N(N不要超过5)。
67
+ *
68
+ **/
69
+ public long fopTimeout ;
70
+
50
71
public PutPolicy (String scope ) {
51
72
this .scope = scope ;
52
73
}
@@ -91,6 +112,12 @@ public String marshal() throws JSONException {
91
112
if (this .persistentOps != null && this .persistentOps .length () > 0 ) {
92
113
stringer .key ("persistentOps" ).value (this .persistentOps );
93
114
}
115
+ if (this .transform != null && this .transform .length () > 0 ) {
116
+ stringer .key ("transform" ).value (this .transform );
117
+ }
118
+ if (this .fopTimeout > 0 ) {
119
+ stringer .key ("fopTimeout" ).value (this .fopTimeout );
120
+ }
94
121
stringer .key ("deadline" ).value (this .deadline );
95
122
stringer .endObject ();
96
123
Original file line number Diff line number Diff line change @@ -64,6 +64,26 @@ public void testPut() throws Exception {
64
64
}
65
65
}
66
66
67
+ /**
68
+ * 这个案例测试上传后转码并将转码结果保存为目标文件。例中使用了 PutPolicy 中的
69
+ * transform 和 fopTimeout 两个参数,分别对应要进行的转码操作和转码超时时间,
70
+ * 测试的时候请将例中的 localFile 改成合法的文件路径。
71
+ **/
72
+ public void testPutTransform () throws Exception {
73
+ PutPolicy putPolicy = new PutPolicy (bucketName );
74
+ putPolicy .transform = "avthumb/mp3" ;
75
+ putPolicy .fopTimeout = 60 ;
76
+
77
+ String uptoken = putPolicy .token (mac );
78
+ String localFile = "/Users/ikbear/7niu/music.mp4" ;
79
+ String key = "music-ikbear.mp3" ;
80
+
81
+ PutExtra extra = new PutExtra ();
82
+
83
+ PutRet ret = IoApi .putFile (uptoken , key , localFile , extra );
84
+ assertTrue (ret .ok ());
85
+ }
86
+
67
87
@ Override
68
88
public void tearDown () {
69
89
// delete the metadata from rs
@@ -89,4 +109,4 @@ public void tearDown() {
89
109
assertTrue (!sr .ok ());
90
110
}
91
111
}
92
- }
112
+ }
You can’t perform that action at this time.
0 commit comments