
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
tcloud-cos-upload
Advanced tools
基于 nodejs
腾讯云上传插件,支持自定义文件前缀、覆盖及非覆盖上传方式
npm install --save tcloud-cos-upload
Step 1. 创建文件 upload.js
const uploadQcloud = require('qcloud-upload');
const options = {
AppId: 'STRING_VALUE',
Region: 'STRING_VALUE',
SecretId: 'STRING_VALUE',
SecretKey: 'STRING_VALUE',
Bucket: 'STRING_VALUE',
Headers: {
CacheControl: 'max-age=31536000'
},
prefix: 'test',
src: './examples',
overWrite: 1
};
uploadQcloud(options);
Step 2. 执行上传操作 node upload.js
Type: Object
AppId
(string): 注册或登录 腾讯云 获取您的AppId,可参考下方说明。SecretId
(string): 到 腾讯云控制台密钥管理 获取您的项目 SecretId 和 SecretKey。SecretKey
(string): 同 SecretId。Bucket
(string): 到 COS 对象存储控制台 创建存储桶,得到 Bucket(存储桶名称) 和 Region(地域名称)。Region
(string): Bucket 所在区域。枚举值请见:Bucket 地域信息。Headers(object)
: 设置头信息,具体 API 参考简单上传-参数说明。prefix
(string): 自定义文件前缀,例如本地文件路径 img.png ,设置了 Prefix: 'demo'
,最终腾讯云路径为 demo/img.png
,默认为空。overWrite
(string): 是否覆盖同名文件,默认 false。src
(string): 上传文件夹相 相对路径,以本项目 examples 文件夹为例,设置 src: './examples'
,上传腾讯云后文件路径为 https://static.demo.com/your-options.prefix/img.png
。(v1.3.0以上版本支持)以下 API 在 v1.3.0+ 版本中废弃:
dirPath
(string): 上传文件夹的 绝对路径 ,以本项目 examples 文件夹为例,应设置 path.resolve(__dirname, './examples')
。distDirName
(string): 截取文件路径参考项,以本项目 examples 文件夹为例,不设置该项,上传腾讯云后文件路径为 https://static.demo.com/your-options.prefix/Users/yingye/Desktop/qcloud-upload/examples/img.png
。若设置该项 distDirName: 'examples'
后,文件URL为 https://static.demo.com/your-options.prefix/examples/img.png
,相当于对 dirPath
绝对路径做了截取操作。AppId
和 Bucket
的说明:腾讯云官方 api 修改,去掉 AppId
概念,Bucket
需要传入这样的格式 test-1250000000
。本插件,兼容两种配置方式,示例如下:
// old api options
const options = {
AppId: 'your AppId',
Bucket: 'old Bucket',
...
};
// new api options
const options = {
Bucket: 'AppId-Bucket',
...
};
该插件基于 腾讯云 COS Nodejs SDK V5 构建,可参考腾讯云官方文档 Node.js SDK。
FAQs
tencent cos upload
We found that tcloud-cos-upload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.