/better_aliyun_oss

A Simple Aliyun OSS Upload for Flutter.

Primary LanguageDartBSD 2-Clause "Simplified" LicenseBSD-2-Clause

better_aliyun_oss

A Simple Aliyun OSS Upload for Flutter.

Install Started

  1. Add this to your pubspec.yaml file:
dependencies:
  better_aliyun_oss: ^0.0.8
  1. Install it
$ flutter packages get

Normal usage

  late BetterAliyunOssClient ossClient;

  late StreamSubscription eventStreamSubscription;

  @override
  void initState() {
    super.initState();

    ossClient = BetterAliyunOssClient(credentials);
    eventStreamSubscription = ossClient.eventStream.listen((event) {
      print("$event");
    });
  }
  
  Future<BetterAliyunOssCredentials?> credentials() async {
    final credentials = {
      "SecurityToken": "",
      "AccessKeyId": "",
      "AccessKeySecret": "",
      "Expiration": "",
    };
    return BetterAliyunOssCredentials.fromMap(credentials);
  }

  void uploading() async {
    final objectFileName = Uuid().v1().replaceAll("-", "") + path.extension(file.path);
    final objectPath = "image/${DateFormat("yyyyMM").format(DateTime.now())}/$objectFileName";

    simplePutRequest = ossClient.putObject(
      bucket: () async => "my-bucket",
      endpoint: () async => "oss-cn-hangzhou.aliyuncs.com",
      domain: () async => "https://domain.com",
      objectPath: objectPath,
      contentType: lookupMimeType(file.path) ?? "application/octet-stream",
      path: file.path,
    );

    print("简单数据上传请求 id : ${simplePutRequest.requestTaskId}");
  }
  
  void cancelSimpleUpload() {
    if (simplePutRequest != null) {
      ossClient.cancelPutObject(simplePutRequest!);
    }
  }

Feature

  • simple upload file to Aliyun OSS.
  • multipart upload file to Aliyun OSS.