@licq/cos
v2.1.5
Published
封装腾讯cos上传相关的方法
Downloads
11
Readme
@licq/cos
基于腾讯 cos nodesdk, 封装批量上传方法,特点是简单,并发效率高
安装
npm i --save-dev @licq/cos
API
Cos
腾讯云对象存储cos上传
Returns: instanceof COS
Since: v2.0.0
| Param | Type | Description | | --- | --- | --- | | Config | Object | 对象存储参数 参考:https://cloud.tencent.com/document/product/436/8629#.E9.85.8D.E7.BD.AE.E9.A1.B9 | | Config.SecretId | String | 必填 | | Config.SecretKey | String | 必填 | | Config.CosObjectConfig | Object | 参见 https://cloud.tencent.com/document/product/436/64980#.E7.AE.80.E5.8D.95.E4.B8.8A.E4.BC.A0.E5.AF.B9.E8.B1.A1 中的参数说明 | | Config.CosObjectConfig.Bucket | String | 必填 | | Config.CosObjectConfig.Region | String | 必填 | | Config.CosObjectConfig.ACL | String | 可选 默认:'public-read' | | Config.ExtConfig | Object | 可选 本工具自定义参数 | | Config.ExtConfig.Domain | String | 可选 上传后的域名 默认:https://{Bucket}.cos.{Region}.myqcloud.com |
Example
const Cos = require('@licq/cos');
const cos = new Cos({
SecretId: "SECRET_ID",
SecretKey: "SECRET_KEY",
CosObjectConfig: {
Bucket: "test-12345678",
Region: "ap-guangzhou",
ACL: 'default'
},
ExtConfig: {
Domain: 'https://demos.gtimg.cn/',
}
});
await cos.uploadFiles(__dirname, 'ost/cos/demo');
cos.uploadFiles(localPath, cosPath)
批量上传
Returns: Promise
| Param | Type | Description | | --- | --- | --- | | localPath | String | 本地文件/目录的绝对路径 | | cosPath | String | cos的path |
cos.uploadFileByData(cosPath, fileData)
通过文件数据上传
Returns: Promise<>
Since: v2.1.3
| Param | Type | Description | | --- | --- | --- | | cosPath | String | cos路径 | | fileData | Buffer | String | Stream | 文件数据 |