tencent_cos_plus

Creator: coderz1093

Last updated:

0 purchases

tencent_cos_plus Image
tencent_cos_plus Images

Languages

Categories

Add to Cart

Description:

tencent cos plus

一个强大的Tencent COS插件,支持Android、iOS、Linux、MacOS、Web、Windows全平台, 实现了bucket接口和object接口的基本操作.
功能 #

支持Bucket接口的基本操作,增加、删除、查询存储桶等
支持Bucket接口的访问控制(acl)
支持Bucket接口的跨域资源共享(cors)
支持Bucket接口的防盗链(referer)
支持Object接口的基本操作,上传、删除、查询存储对象等
支持Object接口的访问控制(acl)
支持扩展其它接口

开始 #
dependencies:
tencent_cos_plus: ^1.2.1
copied to clipboard
import 'package:tencent_cos_plus/tencent_cos_plus.dart';
copied to clipboard
用法 #
初始化 #
COSApiFactory.initialize(
config: COSConfig(
appId: 'xxx',
secretId: 'xxxxxxxxx',
secretKey: 'xxxxxxxxx',
),
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard
Bucket 接口 #

查询请求者名下的所有存储桶列表或特定地域下的存储桶列表

final COSListAllMyBucketsResult result =
await COSApiFactory.bucketApi.getService(region: 'xxx-xxx');
result.buckets?.forEach((element) {
print('${element.name}\b');
});
copied to clipboard

在指定账号下创建一个存储桶

final Response result = await COSApiFactory.bucketApi.putBucket(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

确认该存储桶是否存在,是否有权限访问

final Response result = await COSApiFactory.bucketApi.headBucket();
copied to clipboard

删除指定的存储桶

final Response result = await COSApiFactory.bucketApi.deleteBucket();
copied to clipboard

写入存储桶的访问控制列表(ACL)

final Response result = await COSApiFactory.bucketApi.putBucketACL(
bucketName: 'xxx',
region: 'xxx-xxx',
bucketACLHeader: COSBucketACLHeader()..xCosAcl = 'public-read',
);
copied to clipboard

获取存储桶的访问控制列表(ACL)

final COSAccessControlPolicy result =
await COSApiFactory.bucketApi.getBucketACL(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

为存储桶配置跨域资源共享(CORS)访问控制

final Response result = await COSApiFactory.bucketApi.putBucketCORS(
bucketName: 'xxx',
region: 'xxx-xxx',
corsConfiguration: COSCORSConfiguration(
corsRules: <COSCORSRule>[
COSCORSRule(
allowedOrigins: <String>['*'],
allowedMethods: <String>['PUT', 'GET', 'POST', 'DELETE', 'HEAD'],
allowedHeaders: <String>['*'],
exposeHeaders: <String>[
'ETag',
'Content-Length',
'x-cos-request-id'
],
maxAgeSeconds: 600,
)
],
),
);
copied to clipboard

查询存储桶的跨域资源共享(CORS)访问控制

final COSCORSConfiguration result =
await COSApiFactory.bucketApi.getBucketCORS(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

删除存储桶的跨域资源共享(CORS)访问控制

final Response result = await COSApiFactory.bucketApi.deleteBucketCORS(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

为存储桶设置 Referer 白名单或者黑名单

final COSDomainList domainList = COSDomainList()
..domains = ['*.qcloud.com', '*.qq.com'];
final Response result = await COSApiFactory.bucketApi.putBucketReferer(
bucketName: 'xxx',
region: 'xxx-xxx',
refererConfiguration: COSRefererConfiguration()
..status = 'Enabled'
..refererType = 'White-List'
..domainList = domainList
..emptyReferConfiguration = 'Allow',
);
copied to clipboard

读取存储桶 Referer 白名单或者黑名单。

final COSRefererConfiguration result =
await COSApiFactory.bucketApi.getBucketReferer(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

实现启用或者暂停存储桶的全球加速功能。

final Response response =
await COSApiFactory.bucketApi.putBucketAccelerate(
bucketName: 'xxx',
region: 'xxx-xxx',
accelerateConfiguration: COSAccelerateConfiguration()
..status = 'Enabled',
);
copied to clipboard

实现查询存储桶的全球加速功能配置。

final COSAccelerateConfiguration result =
await COSApiFactory.bucketApi.getBucketAccelerate(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

为存储桶设置键值对作为存储桶标签。

final COSTagSet tagSet = COSTagSet()
..tags = <COSTag>[
COSTag()
..key = 'xxx'
..value = 'xxx'
];
final COSTagging tagging = COSTagging()..tagSet = tagSet;

final Response result = await COSApiFactory.bucketApi.putBucketTagging(
bucketName: 'xxx',
region: 'xxx-xxx',
tagging: tagging,
);
copied to clipboard

查询指定存储桶下已有的存储桶标签。

final COSTagging result = await COSApiFactory.bucketApi.getBucketTagging(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard

删除指定存储桶下已有的存储桶标签。

final Response result = await COSApiFactory.bucketApi.deleteBucketTagging(
bucketName: 'xxx',
region: 'xxx-xxx',
);
copied to clipboard
Object 接口 #

列出该存储桶内的部分或者全部对象

final COSListBucketResult result =
await COSApiFactory.objectApi.listObjects(
bucketName: 'xxx',
region: 'xxx-xxx',
prefix: 'xxx',
);
copied to clipboard

拉取存储桶内的所有对象及其历史版本信息

final COSListVersionsResult result =
await COSApiFactory.objectApi.listObjectVersions(
bucketName: 'xxx',
region: 'xxx-xxx',
prefix: 'xxx',
);
copied to clipboard

将本地的对象(Object)上传至指定存储桶中

final Response result = await COSApiFactory.objectApi.putObject(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
filePath: 'xxx',
);
copied to clipboard

创建一个已存在 COS 的对象的副本

final COSCopyObjectResult result =
await COSApiFactory.objectApi.putObjectCopy(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
xCOSCopySource: 'xxx',
contentType: 'xxx',
);
copied to clipboard

将 COS 存储桶中的对象(Object)下载至本地

final Response result = await COSApiFactory.objectApi.getObject(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
getObject: COSGetObject()..responseCacheControl = 'xxx',
);
copied to clipboard

判断指定对象是否存在和有权限

final Response result = await COSApiFactory.objectApi.headObject(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
);
copied to clipboard

删除一个指定的对象(Object)

final Response result = await COSApiFactory.objectApi.deleteObject(
objectKey: 'xxx',
);
copied to clipboard

批量删除指定存储桶中的多个对象(Object)

var result;
result = await COSApiFactory.objectApi.listObjects(
bucketName: 'xxx',
region: 'xxx-xxx',
prefix: 'xxx',
);
final List<COSObject>? objects = (result as COSListBucketResult)
.contents
?.map<COSObject>((COSContents element) {
print('${element.key} \b');
return COSObject(key: element.key ?? '');
}).toList();
final COSDelete delete =
COSDelete(quiet: false, objects: objects ?? <COSObject>[]);
result = await COSApiFactory.objectApi.deleteMultipleObjects(
bucketName: 'xxx',
region: 'xxx-xxx',
delete: delete,
);
copied to clipboard

用于跨域资源共享(CORS)的预检(Preflight)请求

final Response result = await COSApiFactory.objectApi.optionsObject(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
origin: 'xxx',
accessControlRequestMethod: 'xxx',
);
copied to clipboard

对一个归档存储或深度归档存储类型的对象进行恢复(解冻)以便读取该对象内容

final Response result = await COSApiFactory.objectApi.postObjectRestore(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
restoreRequest: COSRestoreRequest(
days: 10,
casJobParameters: COSCASJobParameters(tier: 'xxx'),
),
);
copied to clipboard

上传文件对象

final Response result = await COSApiFactory.objectApi.putFileObject(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx.png',
filePath: 'xxx.png',
);
copied to clipboard

上传文件夹对象

final Response result = await COSApiFactory.objectApi.putFolderObject(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: '/folder',
);
copied to clipboard

上传目录

final bool result = await COSApiFactory.objectApi.putDirectory(
bucketName: 'xxx',
region: 'xxx-xxx',
directory: '/directory',
);
copied to clipboard

删除目录

final bool result = await COSApiFactory.objectApi.deleteDirectory(
bucketName: 'xxx',
region: 'xxx-xxx',
directory: 'xxx',
);
copied to clipboard

写入对象的访问控制列表(ACL)

final Response result = await COSApiFactory.objectApi.putObjectACL(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
aclHeader: COSACLHeader()..xCosAcl = 'public-read',
);
copied to clipboard

获取对象的访问控制列表(ACL)

final COSAccessControlPolicy result =
await COSApiFactory.objectApi.getObjectACL(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
);
copied to clipboard

为对象添加键值对作为对象标签

final COSTagSet tagSet = COSTagSet()
..tags = <COSTag>[
COSTag()
..key = 'xxx'
..value = 'xxx'
];
final COSTagging tagging = COSTagging()..tagSet = tagSet;

final Response result = await COSApiFactory.objectApi.putObjectTagging(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
tagging: tagging,
versionId: 'xxx',
);
copied to clipboard

查询指定对象下已有的对象标签

final COSTagging result = await COSApiFactory.objectApi.getObjectTagging(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
versionId: 'xxx',
);
copied to clipboard

删除指定对象下已有的对象标签

final Response result = await COSApiFactory.objectApi.deleteObjectTagging(
bucketName: 'xxx',
region: 'xxx-xxx',
objectKey: 'xxx',
versionId: 'xxx',
);
copied to clipboard
扩展其它接口 #

实现具体Api

class XXXApi extends COSAbstractApi with COSApiMixin {
XXXApi(super.config);
}
copied to clipboard

注册具体Api

COSApiFactory.createApi(
key,
XXXApi(COSApiFactory.config),
);
copied to clipboard

使用具体Api

COSApiFactory.get<XXXApi>(key)
copied to clipboard
其它 #
掘金
issues
如果遇到问题,请及时向我们反馈。若此插件对您产生帮助,麻烦为我点亮⭐⭐⭐

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.