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
- upload object
- get object
- save object in files
- delete object
- upload multiple objects at once
- delete multiple objects at once
First, add flutter_oss_aliyun
as a dependency in your pubspec.yaml
file.
dependencies:
flutter_oss_aliyun: ^2.0.3
Don't forget to flutter pub get
.
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"
}
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"
}''';
}
final bytes = "file bytes".codeUnits;
await Client().putObject(bytes, "test.txt");
await Client().getObject("test.txt");
await Client().downloadObject("test.txt", "./example/test.txt");
await Client().deleteObject("test.txt");
await Client().putObjects([
AssetEntity(filename: "filename1.txt", bytes: "files1".codeUnits),
AssetEntity(filename: "filename2.txt", bytes: "files2".codeUnits),
]);
await Client().deleteObjects(["filename1.txt", "filename2.txt"]);