aliossflutter 0.0.3

aliossflutter #

example里的配置文件自行添加配置

///https://help.aliyun.com/document_detail/102082.html?spm=a2c4g.11186623.6.626.15695d26D8hGYE
 static final  String stsserver="";
 ///https://help.aliyun.com/document_detail/31837.html?spm=a2c4g.11186623.6.573.2b6144fdkv167F
 static final String endpoint="";
 ///这是对sts认证的token加密用的key
 ///如果不加密这里不需要
 static final String cryptkey="";
 static final String bucket="";
 static final String key="";
///上传回调配置
///参考 https://help.aliyun.com/document_detail/93985.html?spm=a2c4g.11186623.6.954.390a7c57VfH42B
static final String callbackUrl="";
 static final String callbackHost="";
 ///支持 application/x-www-form-urlencoded 和application/json
 static final String callbackBodyType="application/json";
 static final String callbackBody="{\"j_bucket\":\${bucket},\"j_object\":\${object},\"j_etag\":\${etag},\"j_size\":\${size},\"j_mimeType\":\${mimeType},\"j_height\":\${imageInfo.height},\"j_width\":\${imageInfo.width},\"j_format\":\${imageInfo.format},\"j_memberId\":\${x:var1}}";
 static final String callbackVars="{\"x:var1\":\"123\"}";

阿里云oss 初始化一次就可以了,可以在main.dart里初始化,插件会自动管理sts token过期
后台返回sts格式:

{
 "StatusCode": 200,
 "AccessKeyId":"STS.iA645eTOXEqP3cg3VeHf",
 "AccessKeySecret":"rV3VQrpFQ4BsyHSAvi5NVLpPIVffDJv4LojUBZCf",
 "Expiration":"2015-11-03T09:52:59Z",
 "SecurityToken":"CAES7QIIARKAAZPlqaN9ILiQZPS+JDkS/GSZN45RLx4YS/p3OgaUC+oJl3XSlbJ7StKpQ...."
}

加密sts返回格式:

{
 "Data": "3des加密后的 sts"
}

初始化

import 'package:aliossflutter/aliossflutter.dart';
AliOSSFlutter  alioss=AliOSSFlutter();
alioss.init("sts url", "http://oss-cn-hangzhou.aliyuncs.com");
//可选一种 sts token 3DES加密方式
//alioss.init("sts url", "http://oss-cn-hangzhou.aliyuncs.com",cryptkey:"key");
//监听初始化
alioss.responseFromInit.listen((data){
      if(data) { 
          _msg="初始化成功"; 
      }else{
        _msg="初始化失败";
      }
    });

上传

AliOSSFlutter  alioss=AliOSSFlutter();
alioss.upload("bucket", file.path, "key",callbackBody: Config.callbackBody,callbackBodyType: Config.callbackBodyType,callbackHost: Config.callbackHost,callbackUrl: Config.callbackUrl,callbackVars: Config.callbackVars);
//监听上传
alioss.responseFromUpload.listen((data) {
      if(data.success) {
        setState(() {
          _msg="上传成功 key:"+data.key+" 服务器回调返回值:"+data.servercallback;
        });
      }else{
        _msg="上传失败";
      }
    });

下载

AliOSSFlutter  alioss=AliOSSFlutter();
alioss.download(bucket, key, path,{process = ""});
//监听下载回调
alioss.responseFromDownload.listen((data) {
      if(data.success) {
        setState(() {
          _path=data.path;
          _msg="下载成功:"+_path;
        });
      }else{
        _msg="下载失败";
      }
    });

url签名:

//type=1 签名私有资源
//type=0 签名公开的访问URL
alioss.signUrl(bucket, key,{type = "0",interval = "1800",process = ""})

//监听url签名
alioss.responseFromSign.listen((data){
      if(data.success) {
        setState(() {
          _msg="url 签名 :"+data.url;
        });
      }else{
        _msg="url 签名失败";
      }
    });

监听进度上传和下载共用

alioss.responseFromProgress.listen((data){
if(data.key==key) {
 setState(() {
  _progress=data.getProgress();
 });
 }
});

判断文件是否存在

alioss.exist(bucket, key).then((exist) {
      if (exist) {
        _msg = "已存在";
      } else if (!exist) {
        _msg = "不存在";
      }
      setState(() {});
    }).catchError((err) {
      _msg = "错误:$err";
      setState(() {});
    });

写了个插件开发过程,可以参考下 插件开发方法.

0.0.2 #

增加判断文件是否存在

0.0.1 #

  • TODO: Describe initial release.

example/README.md

aliossflutter_example #

Demonstrates how to use the aliossflutter plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  aliossflutter: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:aliossflutter/aliossflutter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
44
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Aug 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

74 out of 74 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/aliossflutter.dart. (-3.45 points)

Analysis of lib/aliossflutter.dart reported 7 hints, including:

line 18 col 26: Close instances of dart.core.Sink.

line 23 col 38: Close instances of dart.core.Sink.

line 28 col 38: Close instances of dart.core.Sink.

line 33 col 36: Close instances of dart.core.Sink.

line 38 col 34: Close instances of dart.core.Sink.

Format lib/response.dart.

Run flutter format to format lib/response.dart.

Maintenance issues and suggestions

The description contains too many non-ASCII characters. (-20 points)

The site uses English as its primary language. The value of the description field in your package's pubspec.yaml field should primarily contain characters used in English.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
uuid ^2.0.0 2.0.2
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.2
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8