1.3.2 • Published 1 year ago

qcloud-cos-upload v1.3.2

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year ago

qcloud-cos-upload

npm version Build Status semantic-release

上传单个文件到腾讯云COS服务,用于静态文件上传。

releases and changelog

Tips

适配腾讯云官方 COS Nodejs SDK(XML API) cos-nodejs-sdk-v5

批量上传文件参见 gulp-qcloud-cos-upload

为安全起见,建议为每个存储桶提供独立的子账号,使用子账号的 SecretId 和 SecretKey 来上传文件。

创建子账号

在存储桶配置的权限管理页卡配置存储桶访问权限Policy权限设置,提供子账号的访问权限。

Getting Started

安装:

npm i qcloud-cos-upload

选项配置参见 腾讯云存储说明文档

使用:

const upload = require('qcloud-cos-upload');

upload({
  // 是否开启调试模式,默认为 false,调试模式下,报错时输出详细错误信息
  debug: false,
  // 是否在控制台打印上传日志,默认为 true
  log: true,
  // 是否允许文件覆盖,默认为 false
  overwrite: false,
  // 为 true 则输出文件路径为腾讯云默认 CDN 地址。为具体域名,则替换腾讯云默认 CDN 域名。
  cdn: '',
  // 文件远程路径协议,默认为 'https:',这个选项仅影响输出结果。
  protocol: 'https:',
  // 在腾讯云申请的 AppId
  AppId: '1000000000',
  // 配置腾讯云 COS 服务所需的 SecretId
  SecretId: 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  // 配置腾讯云 COS 服务所需的 SecretKey
  SecretKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  // COS服务配置的存储桶名称
  Bucket: 'static',
  // 地域名称
  Region: 'ap-chengdu',
  // 要上传的本地文件路径
  FilePath: './1.zip',
  // 文件在存储桶中的路径
  Key: '1.zip'
}).then(rs => {
  // 线上路径
  console.info(rs.url);
  // 为 true 表明线上文件已存在
  console.info(rs.isExists);
  // 为 true 表明进行了覆盖
  console.info(rs.overwrited);
  // 为 true 表明已进行了上传
  console.info(rs.uploaded);
  // 文件在对象存储的线上访问路径
  console.info(rs.cosUrl);
  // 文件在 CDN 的线上访问路径,如果没有配置 cdn 选项则为 undefined
  console.info(rs.cdnUrl);
  // 如果进行了上传,可以通过 uploadData 取得详细上传信息
  console.info(rs.uploadData);
});
1.3.2

1 year ago

1.3.1

4 years ago

1.3.0

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago

0.1.0

7 years ago