flutter_oss_aliyun 4.1.0 copy "flutter_oss_aliyun: ^4.1.0" to clipboard
flutter_oss_aliyun: ^4.1.0 copied to clipboard

oss aliyun plugin for flutter and upport STS to access OSS temporarily

Language: English | 中文简体

flutter_oss_aliyun #

Oss aliyun plugin for flutter. Use sts policy to authenticate the user.

flutter pub: https://pub.dev/packages/flutter_oss_aliyun

oss sts document: https://help.aliyun.com/document_detail/100624.html

Feature #

  • upload object
  • get object
  • save object in files
  • delete object
  • upload multiple objects at once
  • delete multiple objects at once
  • progress callback for uploading files
  • progress callback for downloading files
  • get signed url for file
  • get multiple signed urls for files
  • list objects
  • get bucket info
  • get bucket stat

Usage #

First, add flutter_oss_aliyun as a dependency in your pubspec.yaml file.

dependencies:
  flutter_oss_aliyun: ^4.1.0

Don't forget to flutter pub get.

1. init the client, we provide two ways to do it. #

use sts server, just provide the sts url from our backend server:

Client.init(
    stsUrl: "server url get sts token",
    ossEndpoint: "oss-cn-beijing.aliyuncs.com",
    bucketName: "bucket name",
);

This sts url api at least return the data:

{
  "AccessKeyId": "AccessKeyId",
  "AccessKeySecret": "AccessKeySecret",
  "SecurityToken": "SecurityToken",
  "Expiration": "2022-03-22T11:33:06Z"
}

you can also customize the way to get sts json response.

Client.init(
    ossEndpoint: "oss-cn-beijing.aliyuncs.com",
    bucketName: "bucketName",
    tokenGetter: _tokenGetterMethod
);

String _tokenGetterMethod() async {
  return '''{
        "AccessKeyId": "access id",
        "AccessKeySecret": "AccessKeySecret",
        "SecurityToken": "security token",
        "Expiration": "2022-03-22T11:33:06Z"
    }''';
}

2. put the object to oss with progress callback #

final bytes = "file bytes".codeUnits;

await Client().putObject(
  bytes, 
  "test.txt",
  onSendProgress: (count, total) {
    debugPrint("sent = $count, total = $total");
  },
  onReceiveProgress: (count, total) {
    debugPrint("received = $count, total = $total");
  }
);

3. get the object from oss with progress callback #

await Client().getObject(
  "test.txt",
  onReceiveProgress: (count, total) {
    debugPrint("received = $count, total = $total");
  },
);

4. download the object from oss with progress callback #

await Client().downloadObject(
  "test.txt", 
  "./example/test.txt",
  onReceiveProgress: (count, total) {
    debugPrint("received = $count, total = $total");
  },
);

5. delete the object from oss #

await Client().deleteObject("test.txt");

6. batch put the object to oss #

await Client().putObjects(
  [
    AssetEntity(filename: "filename1.txt", bytes: "files1".codeUnits),
    AssetEntity(filename: "filename2.txt", bytes: "files2".codeUnits),
  ],
  onSendProgress: (count, total) {
    debugPrint("sent = $count, total = $total");
  },
  onReceiveProgress: (count, total) {
    debugPrint("received = $count, total = $total");
  },
);

7. batch delete the object from oss #

await Client().deleteObjects(["filename1.txt", "filename2.txt"]);

8. get signed url that can be accessed in browser directly #

This is not safe due to the url include the security-token information even it will expire in short time. Use it carefully!!!

final String url = await Client().getSignedUrl("filename1.txt");

9. get multiple signed urls #

This is not safe due to the url include the security-token information even it will expire in short time. Use it carefully!!!

final Map<String, String> result = await Client().getSignedUrls(["test.txt", "filename1.txt"]);

10. list objects #

List the information of all files (Object) in the storage space (Bucket). The parameters and response, refer to: https://help.aliyun.com/document_detail/187544.html

final Response<dynamic> resp = await Client().listFiles({});

11. get bucket info #

View bucket information, The response refer to:https://help.aliyun.com/document_detail/31968.html

final Response<dynamic> resp = await Client().getBucketInfo();

12. get objects counts and bucket details #

Gets the storage capacity of the specified storage space (Bucket) and the number of files (Object), The response refer to:https://help.aliyun.com/document_detail/426056.html

final Response<dynamic> resp = await Client().getBucketStat();

Drop a ⭐ if it is help to you. #

44
likes
0
pub points
92%
popularity

Publisher

verified publisherhuhx.cn

oss aliyun plugin for flutter and upport STS to access OSS temporarily

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

crypto, dio, flutter, mime_type

More

Packages that depend on flutter_oss_aliyun