npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qiao-cos

v4.6.6

Published

tencent cos upload tool on nodejs

Downloads

62

Readme

qiao-cos

npm version npm downloads

nodejs 下腾讯云 cos 常见 api 封装

install

安装

npm i qiao-cos

config.json

配置文件

{
    "SecretId": "your secret id",
    "SecretKey": "your secret key",
    "Region": "your bucket",
    "Bucket": "your bucket",
}

cli

也支持cli使用,详见qiao-cos-cli

use

使用

// cjs
const COS = require('qiao-cos');

// mjs
import COS from 'qiao-cos';

qcos

实例

// config
const config = require('./config.json');

// qiao-cos
const qcos = COS(config);

sts

认证相关

getCredential

获取临时秘钥

  • durationSeconds
    • 类型: number
    • 说明: 秘钥过期时间,单位秒,默认为1800
  • allowPrefix
    • 类型: string
    • 说明: 允许访问的地址前缀
  • return
    • 类型: object
    • 说明: 临时秘钥等数据
const sts = await qcos.getCredential(durationSeconds, allowPrefix);

cdn

cdn相关操作

cdnSign

cos配套的cdn鉴权

  • destPath
    • 类型: string
    • 说明: cos 的目标路径,这里以/开头
  • timeout
    • 类型: number
    • 说明: 有效时间,单位是秒
  • return
    • 类型: string
    • 说明: 添加sign和t后的url
  • 备注
const destPath = '/202309/2e266e54-8ddc-42d9-a772-a24514c5d17b.png';

// timeout is 0
const url = qcos.cdnSign(destPath);

// timeout is 10s
const url = qcos.cdnSign(destPath, 10);

bucket

bucket相关操作

listBuckets

列出存储桶

  • return
    • 类型: object
    • 说明: 存储桶相关信息
const res = await qcos.listBuckets();

listObjects

列出对象列表

  • prefix
    • 类型: string
    • 说明: 筛选的前缀
  • max
    • 类型: number
    • 说明: 单次返回最大条数,默认1000,最大1000
  • marker
    • 类型: string
    • 说明: 上次返回的结尾
  • return
    • 类型: object
    • 说明: 对象相关信息
const res = await qcos.listObjects();

listObjectsAll

列出所有对象

  • prefix
    • 类型: string
    • 说明: 筛选的前缀
  • max
    • 类型: number
    • 说明: 单次返回最大条数,默认1000,最大1000
  • return
    • 类型: object
    • 说明: 对象相关信息
const res = await qcos.listObjectsAll();

object

object相关操作

delObject

删除对象

  • key
    • 类型: string
    • 说明: 对象名称
  • return
    • 类型: object
    • 说明: 删除结果
const res = await qcos.delObject(key);

upload

uploadFile

上传文件

  • destPath
    • 类型: string
    • 说明: cos 的目标路径
  • sourceFile
    • 类型: string
    • 说明: 待上传的文件路径
  • return
    • 类型: object
    • 说明: cos 返回的结果
const destPath = 'test/test.js';
const sourceFile = '/your/test.js';

const rs = await qcos.uploadFile(destPath, sourceFile);
console.log(rs);

uploadFolder

上传文件夹

  • destPath
    • 类型: string
    • 说明: cos 的目标路径
  • sourceFolder
    • 类型: string
    • 说明: 待上传的文件夹路径
  • return
    • 类型: object
    • 说明: cos 返回的结果
const destPath = 'test';
const sourceFolder = '/your/folder';

const rs = await qcos.uploadFolder(destPath, sourceFolder);
console.log(rs);