UPYUN Android SDK, 集成:
1.SDK 依赖 okhttp。
2.SDK 已经上传 Jcenter,Android Studio 的用户可以直接在 gradle 中添加一条 dependencies:
implementation 'com.upyun:upyun-android-sdk:2.1.4'
3.DEMO 示例在 app module 下的 MainActivity。
在 UpConfig 中可以对 SDK 的一些参数进行配置。
BLOCK_SIZE
单个分块大小CONCURRENCY
上传线程并发数量EXPIRATION
默认过期时间偏移量(秒)FORM_HOST
表单上传 HOSTRETRY_TIME
失败重传次数CONNECT_TIMEOUT
连接超时(秒)READ_TIMEOUT
读超时(秒)WRITE_TIMEOUT
写超时(秒)
//表单上传(本地签名方式)
UploadEngine.getInstance().formUpload(temp, paramsMap, OPERATER, UpYunUtils.md5(PASSWORD), completeListener, progressListener);
//表单上传(服务器签名方式)
UploadEngine.getInstance().formUpload(temp, policy, OPERATER, signature, completeListener, progressListener);
参数说明:
temp
上传文件paramsMap
参数键值对OPERATER
操作员PASSWORD
操作员密码(MD5后传入)completeListener
结束回调(回调到 UI 线程,不可为 NULL)progressListener
进度条回调(回调到 UI 线程,可为 NULL)policy
从服务器获取的 policy(生成规则见官网文档)signature
从服务器获取的 signature(生成规则见官网文档 注:Authorization = UPYUN 操作员:signature)
//初始化断点续传
SerialUploader serialUploader = new SerialUploader(SPACE,OPERATER,UpYunUtils.md5(PASSWORD));
//设置 MD5 校验(服务端签名方式不可校验 MD5)
serialUploader.setCheckMD5(true);
//设置进度监听
serialUploader.setOnProgressListener(new ResumeUploader.OnProgressListener() {
@Override
public void onProgress(int index, int total) {
}
});
//暂停
serialUploader.pause()
//开始断点续传,可用方法 1 或方法 2
//方法 1
serialUploader.upload(final File file, final String uploadPath, final Map<String, String> restParams, final UpCompleteListener completeListener)
//方法 2
serialUploader.upload(final File file, final String uploadPath, final Map<String, String> restParams, final Map<String, Object> processParam, final UpCompleteListener completeListener)
//初始化断点续传
ParallelUploader parallelUploader = new ParallelUploader(SPACE,OPERATER,UpYunUtils.md5(PASSWORD));
//初始化断点续传 (服务端签名可用)
ParallelUploader parallelUploader = new ParallelUploader();
//设置 MD5 校验(服务端签名方式不可校验 MD5)
parallelUploader(true);
//设置进度监听
parallelUploader(new ResumeUploader.OnProgressListener() {
@Override
public void onProgress(int index, int total) {
}
});
//暂停
parallelUploader.pause()
//开始断点续传,可用方法 1 或方法 2
//方法 1
parallelUploader(final File file, final String uploadPath, final Map<String, String> restParams, final UpCompleteListener completeListener)
//方法 2
parallelUploader(final File file, final String uploadPath, final Map<String, String> restParams, final Map<String, Object> processParam, final UpCompleteListener completeListener)
//服务端签名方式
parallelUploader.upload(final File file, final String uri, final String date, final String signature, final Map<String, String> restParams, final UpCompleteListener completeListener)
参数说明:
file
上传文件uploadPath
上传路径restParams
rest api 上传预处理参数可为空 (详见文档)processParam
异步音视频处理参数 (详见文档)completeListener
结束回调(回调到 UI 线程,不可为 NULL)
服务器签名参数:
uri
请求路径(带空间名)date
请求日期时间signature
服务端签名(注:Authorization = UPYUN 操作员:signature)
./gradlew connectedAndroidTest
请参照 API 错误码表
Android 2.3(API10) 以上环境