Coder Social home page Coder Social logo

android-sdk's Introduction

UPYUN Android SDK

Build Status Download

UPYUN Android SDK, 集成:

使用说明:

1.直接下载 JAR 包复制进项目使用, SDK 依赖 okhttp

2.SDK 已经上传 Jcenter,Android Studio 的用户可以直接在 gradle 中添加一条 dependencies:

compile 'com.upyun:upyun-android-sdk:1.0.2'

参数设置

UpConfig 中可以对 SDK 的一些参数进行配置。

  • BLOCK_SIZE 单个分块大小
  • FILE_BOUND 自动判断使用分块或者表单上传的文件大小界限
  • CONCURRENCY 上传线程并发数量
  • EXPIRATION 默认过期时间偏移量(秒)
  • FORM_HOST 表单上传 HOST
  • BLOCK_HOST 分块上传 HOST
  • RETRY_TIME 失败重传次数
  • CONNECT_TIMEOUT 连接超时(秒)
  • READ_TIMEOUT 读超时(秒)
  • WRITE_TIMEOUT 写超时(秒)

上传接口

详细示例请见 app module 下的 MainActivity

表单上传

UploadManager.getInstance().formUpload(new File(localFilePath), paramsMap, KEY, completeListener, progressListener);
UploadManager.getInstance().formUpload(new File(localFilePath), paramsMap, signatureListener, completeListener, progressListener);

使用该方法,直接选择通过表单上传方式上传文件。

参数说明:

  • localFilePath 文件路径
  • paramsMap 参数键值对
  • KEY 表单 API 验证密钥(form_api_secret)
  • signatureListener 获取签名回调
  • completeListener 结束回调(回调到 UI 线程,不可为 NULL)
  • progressListener 进度条回调(回调到 UI 线程,可为 NULL)

两种上传方式可根据自己情况选择一种,KEY 用户可直接保存在客户端,signatureListener 用户可以通过请求服务器获取签名返回客户端。signatureListener 回调接口规则如下:

SignatureListener signatureListener=new SignatureListener() {
    @Override
    public String getSignature(String raw) {
        return UpYunUtils.md5(raw+KEY);
    }
};

将参数 raw 传给后台服务器和表单密匙连接后做一次 md5 运算返回结果。

参数键值对中 Params.BUCKET(上传空间名)和 Params.SAVE_KEYParams.PATH(保存路径,任选一个)为必选参数, 其他可选参数见 Params 或者官网 API 文档

分块上传

UploadManager.getInstance().blockUpload(new File(localFilePath), paramsMap, KEY, completeListener, progressListener);
UploadManager.getInstance().blockUpload(new File(localFilePath), paramsMap, signatureListener, completeListener, progressListener);

使用该方法,直接选择通过分块上传方式上传文件。 参数说明:同上。

测试

./gradlew connectedAndroidTest

错误码说明

请参照 API 错误码表

兼容性

Android 2.3(API10) 以上环境

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.