编程随笔 编程随笔
  • 前端
  • 后端
  • 星球项目
  • 开源项目
  • 海康AGV
  • 四向车
  • 工具类
  • 项目仓库

    • 部署仓库 (opens new window)
    • 代码仓库 (opens new window)
  • vuepress插件

    • 自动生成导航栏与侧边栏 (opens new window)
    • 评论系统 (opens new window)
    • 全文搜索 (opens new window)
    • 选项卡 (opens new window)
    • 自动生成sitemap (opens new window)
  • 自主开发插件

    • 批量操作frontmatter (opens new window)
    • 链接美化 (opens new window)
    • 折叠代码块 (opens new window)
    • 复制代码块 (opens new window)

liyao52033

走运时,要想到倒霉,不要得意得过了头;倒霉时,要想到走运,不必垂头丧气。心态始终保持平衡,情绪始终保持稳定,此亦长寿之道
  • 前端
  • 后端
  • 星球项目
  • 开源项目
  • 海康AGV
  • 四向车
  • 工具类
  • 项目仓库

    • 部署仓库 (opens new window)
    • 代码仓库 (opens new window)
  • vuepress插件

    • 自动生成导航栏与侧边栏 (opens new window)
    • 评论系统 (opens new window)
    • 全文搜索 (opens new window)
    • 选项卡 (opens new window)
    • 自动生成sitemap (opens new window)
  • 自主开发插件

    • 批量操作frontmatter (opens new window)
    • 链接美化 (opens new window)
    • 折叠代码块 (opens new window)
    • 复制代码块 (opens new window)
  • springboot

  • 服务器相关

  • 腾讯云cos对象操作

    • 初始化客户端
    • 文件上传
    • 文件下载
    • 文件删除
    • NodeJs获取签名
  • 后端
  • 腾讯云cos对象操作
华总
2024-01-14
0
0

NodeJs获取签名原创

1、安装cos的nodejs依赖

yarn add cos-nodejs-sdk-v5 -D
1
npm i cos-nodejs-sdk-v5 --save
1

2、使用

const COS = require('cos-nodejs-sdk-v5')

const cos = new COS({
      SecretId: config.secretId,
      SecretKey: config.secretKey,
      // 是否自定义域名
      Domain: config.customUrl ? config.customUrl : ''
 })

    const key = (config.path ? config.path : '') + img.fileName

    // 去掉问号
    const queryStr = config.path?.startsWith('?') ? config.path.substring(1) : config.path
    const query = new Map(queryStr.split('&').map(value => {
      const arr = value.split('=')
      return [arr[0], arr]
    }))

    let url = cos.getObjectUrl({
      Bucket: config.bucket,
      Region: config.area,
      Key: key,
      Sign: true,
      Query: query,
      Expires: expireSeconds
    }, (err, data) => {
      if (err) {
        ctx.log.warn(err.message)
      }
      url = data.Url
    })
    return url
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
上次更新: 2024/01/14 17:13:46
文件删除

← 文件删除

最近更新
01
element-plus多文件手动上传 原创
11-03
02
TrueLicense 创建及安装证书 原创
10-25
03
手动修改迅捷配置 原创
09-03
04
安装 acme.sh 原创
08-29
05
zabbix部署 原创
08-20
更多文章>
Copyright © 2023-2024 liyao52033
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式