Skip to content

qiniu/java-sdk

Repository files navigation

Qiniu Resource Storage SDK for Java

@qiniu on weibo Software License Build Status GitHub release Docs Coverage Status Latest Stable Version

安装

下载 the latest JAR 或者 通过 Maven:

<dependency>
  <groupId>com.qiniu</groupId>
  <artifactId>qiniu-java-sdk</artifactId>
  <version>[7.15.0, 7.15.99]</version>
</dependency>

或者 Gradle:

implementation 'com.qiniu:qiniu-java-sdk:7.15.+'

运行环境

JDK 7 及以上

使用方法

上传

// 分片上传 v1
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.qiniu.storage.Configuration;
import com.qiniu.http.Response;

String accessKey = "Your AccessKey";
String secretKey = "Your SecretKey";
String bucketName = "upload to bucket";
Configuration cfg = new Configuration();
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(accessKey, secretKey);
String token = auth.uploadToken(bucketName);
String key = "file save key";
Response r = uploadManager.put("hello world".getBytes(), key, token);

// 分片上传 v2
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.qiniu.storage.Configuration;
import com.qiniu.http.Response;

String accessKey = "Your AccessKey";
String secretKey = "Your SecretKey";
String bucketName = "upload to bucket";
Configuration cfg = new Configuration();
cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(accessKey, secretKey);
String token = auth.uploadToken(bucketName);
String key = "file save key";
Response r = uploadManager.put("hello world".getBytes(), key, token);

其他使用请参考[开发指南]https://developer.qiniu.com/kodo/1239/java 详细的示例请参考[Examples]https://github.com/qiniu/java-sdk/tree/master/examples

测试

$ ./gradlew build

生成Eclipse工程文件

$ ./gradlew gen_eclipse

常见问题

  • QiniuExeption保留了请求响应的信息,失败情况下会抛出此异常,可以提交给我们排查问题。
  • API 的使用 demo 可以参考 单元测试

代码贡献

详情参考代码提交指南

贡献记录

联系我们

  • 如果需要帮助,请提交工单(在portal右侧点击咨询和建议提交工单,或者直接向 support@qiniu.com 发送邮件)
  • 如果有什么问题,可以到问答社区提问,问答社区
  • 更详细的文档,见官方文档站
  • 如果发现了bug, 欢迎提交 issue
  • 如果有功能需求,欢迎提交 issue
  • 如果要提交代码,欢迎提交 pull request
  • 欢迎关注我们的微信 微博,及时获取动态信息。

代码许可

The MIT License (MIT).详情见 License文件.