Skip to content

Commit 1d2eafb

Browse files
committed
Merge pull request #115 from qiniu/develop
Release 6.1.4
2 parents 68864b5 + 713f7fe commit 1d2eafb

File tree

5 files changed

+25
-124
lines changed

5 files changed

+25
-124
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
## 使用
2626

27-
参考文档:[七牛云存储 Java SDK 使用指南](http://docs.qiniutek.com/v2/sdk/java/)
27+
参考文档:[七牛云存储 Java SDK 使用指南](http://developer.qiniu.com/docs/v6/sdk/java-sdk.html)
2828

2929

3030
## 贡献代码

docs/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,32 @@ public class UploadFile {
209209

210210
### 3.4 断点续上传、分块并行上传
211211

212-
建设中...
212+
与普通上传类似:
213+
```{java}
214+
private void uploadFile() throws AuthException, JSONException{
215+
PutPolicy p = new PutPolicy(bucketName);
216+
p.returnBody = "{\"key\": $(key), \"hash\": $(etag),\"mimeType\": $(mimeType)}";
217+
String upToken = p.token(mac);
218+
PutRet ret = ResumeableIoApi.put(file, upToken, key, mimeType);
219+
}
220+
221+
private void uploadStream() throws AuthException, JSONException, FileNotFoundException{
222+
PutPolicy p = new PutPolicy(bucketName);
223+
String upToken = p.token(mac);
224+
FileInputStream fis = new FileInputStream(file);
225+
PutRet ret = ResumeableIoApi.put(fis, upToken, key, mimeType);
226+
}
227+
228+
```
229+
key,mimeType 可为null。
213230

214231
<a name="io-put-policy"></a>
215232

216233
### 3.5 上传策略
217234

218235
[uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 实际上是用 AccessKey/SecretKey 进行数字签名的上传策略(`rs.PutPolicy`),它控制则整个上传流程的行为。让我们快速过一遍你都能够决策啥:
219236

220-
* `expires` 指定 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 有效期(默认1小时)。一个 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 可以被用于多次上传(只要它还没有过期)。
221-
* `scope` 限定客户端的权限。如果 `scope` 是 bucket,则客户端只能新增文件到指定的 bucket,不能修改文件。如果 `scope` 为 bucket:key,则客户端可以修改指定的文件。**注意: key必须采用utf8编码,如使用非utf8编码访问七牛云存储将反馈错误**
222-
* `callbackUrl` 设定业务服务器的回调地址,这样业务服务器才能感知到上传行为的发生。可选。
223-
* `asyncOps` 可指定上传完成后,需要自动执行哪些数据处理。这是因为有些数据处理操作(比如音视频转码)比较慢,如果不进行预转可能第一次访问的时候效果不理想,预转可以很大程度改善这一点。
224-
* `returnBody` 可调整返回给客户端的数据包(默认情况下七牛返回文件内容的 `hash`,也就是下载该文件时的 `etag`)。这只在没有 `CallbackUrl` 时有效。
225-
* `escape` 为真(非0)时,表示客户端传入的 `callbackParams` 中含有转义符。通过这个特性,可以很方便地把上传文件的某些元信息如 `fsize`(文件大小)、`ImageInfo.width/height`(图片宽度/高度)、`exif`(图片EXIF信息)等传给业务服务器。
226-
* `detectMime` 为真(非0)时,表示服务端忽略客户端传入的 `mimeType`,自己自行检测。
237+
* `expires` 指定 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 有效时长。单位:秒(s),默认1小时,3600秒。deadline = System.currentTimeMillis() / 1000 + this.expires,不直接指定deadline。一个 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken) 可以被用于多次上传(只要它还没有过期)。
227238

228239
关于上传策略更完整的说明,请参考 [uptoken](http://docs.qiniu.com/api/put.html#uploadToken)
229240

src/main/java/com/qiniu/api/config/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Config {
2323

2424
public static String RS_HOST = "http://rs.qbox.me";
2525

26-
public static String UP_HOST = "http://up.qbox.me";
26+
public static String UP_HOST = "http://up.qiniu.com";
2727

2828
public static String RSF_HOST = "http://rsf.qbox.me";
2929

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

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,17 @@ public class PutPolicy {
4141
public int detectMime;
4242
/** 可选 */
4343
public long fsizeLimit;
44-
/**限定用户上传的文件类型
44+
/**限定用户上传的文件类型
4545
* 可选
4646
* */
4747
public String mimeLimit;
4848
/** 可选 */
4949
public String persistentNotifyUrl;
5050
/** 可选 */
5151
public String persistentOps;
52-
53-
public long deadline;
5452

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

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

7756
public PutPolicy(String scope) {
7857
this.scope = scope;
@@ -121,27 +100,21 @@ public String marshal() throws JSONException {
121100
if (this.persistentOps != null && this.persistentOps.length() > 0) {
122101
stringer.key("persistentOps").value(this.persistentOps);
123102
}
124-
if (this.transform != null && this.transform.length() > 0) {
125-
stringer.key("transform").value(this.transform);
126-
}
127-
if (this.fopTimeout > 0) {
128-
stringer.key("fopTimeout").value(this.fopTimeout);
129-
}
130103
stringer.key("deadline").value(this.deadline);
131104
stringer.endObject();
132105

133106
return stringer.toString();
134107
}
135108

136-
109+
137110
/**
138111
* makes an upload token.
139112
* @param mac
140113
* @return
141114
* @throws AuthException
142115
* @throws JSONException
143116
*/
144-
117+
145118
public String token(Mac mac) throws AuthException, JSONException {
146119
if (this.expires == 0) {
147120
this.expires = 3600; // 3600s, default.

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

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)