Skip to content

Release 6.1.4 #115

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 8 commits into from
May 30, 2014
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

## 使用

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


## 贡献代码
Expand Down
27 changes: 19 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,32 @@ public class UploadFile {

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

建设中...
与普通上传类似:
```{java}
private void uploadFile() throws AuthException, JSONException{
PutPolicy p = new PutPolicy(bucketName);
p.returnBody = "{\"key\": $(key), \"hash\": $(etag),\"mimeType\": $(mimeType)}";
String upToken = p.token(mac);
PutRet ret = ResumeableIoApi.put(file, upToken, key, mimeType);
}

private void uploadStream() throws AuthException, JSONException, FileNotFoundException{
PutPolicy p = new PutPolicy(bucketName);
String upToken = p.token(mac);
FileInputStream fis = new FileInputStream(file);
PutRet ret = ResumeableIoApi.put(fis, upToken, key, mimeType);
}

```
key,mimeType 可为null。

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

### 3.5 上传策略

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/api/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Config {

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

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

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

Expand Down
35 changes: 4 additions & 31 deletions src/main/java/com/qiniu/api/rs/PutPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,17 @@ public class PutPolicy {
public int detectMime;
/** 可选 */
public long fsizeLimit;
/**限定用户上传的文件类型
/**限定用户上传的文件类型
* 可选
* */
public String mimeLimit;
/** 可选 */
public String persistentNotifyUrl;
/** 可选 */
public String persistentOps;

public long deadline;

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

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

public PutPolicy(String scope) {
this.scope = scope;
Expand Down Expand Up @@ -121,27 +100,21 @@ 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();

return stringer.toString();
}


/**
* makes an upload token.
* @param mac
* @return
* @throws AuthException
* @throws JSONException
*/

public String token(Mac mac) throws AuthException, JSONException {
if (this.expires == 0) {
this.expires = 3600; // 3600s, default.
Expand Down
83 changes: 0 additions & 83 deletions src/test/java/com/qiniu/testing/TransformTest.java

This file was deleted.