Giter VIP home page Giter VIP logo

flutter_oss_sdk's Introduction

阿里云Oss插件

代码示例

class OssTest {
  //全局初始化
  static void init() {
    ClientConfig config = ClientConfig(
        endPoint: 'https://xxx.aliyuncs.com',
        bucket: 'yourBucket',
        authorizationProvider: TestAuthorizationProvider()
        );
    OssClient.init(config);
  }

  //上传
  static void upload() {
    PutObjectRequest request =
        PutObjectRequest('test.jpg', '/storage/emulated/0/test.jpg');
    OssClient.instance.putObject(request,
        onSucceed: (PutObjectResponse result) {
        print("upload success:${result.url}");
        }, onFailed: (String msg) {
      print("上传失败:$msg");
    }, onProgress: (int count, int total) {
      double progress = count * 100 / total;
      print("count=$count ---total=$total---progress=$progress");
    });
  }

  //下载
  static void download(){
    GetObjectRequest request =
   GetObjectRequest('test.jpg', '/storage/emulated/0/test1112.jpg',isAuthorizationRequired: false);
   OssClient.instance.getObject(request, onSucceed: () {
     print("下载成功");
   }, onFailed: (String msg) {
     print("下载失败");
   }, onProgress: (int count, int total) {
     double progress = count * 100 / total;
     print("count=$count ---total=$total---progress=$progress");
   });
  }


}

class TestAuthorizationProvider implements AuthorizationProvider {
  @override
  Future<OssToken> getAuthorization() async {
    String tempAk;
    String tempSk;
    String securityToken;
    String expiration;
    await NetUtils.instance.get(NetUrl.OSS_TOKEN, onSuccess: (data) {
       tempAk = data['AccessKeyId'];
       tempSk = data['AccessKeySecret'];
       securityToken = data['SecurityToken'];
       expiration = data['Expiration'];
     });
    return OssToken(
        tempAk: tempAk,
        tempSk: tempSk,
        securityToken: securityToken,
        expiration: expiration);
  }
}

flutter_oss_sdk's People

Contributors

nasdaqhe avatar whqfor avatar zcys12173 avatar

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.