import COS from 'cos-js-sdk-v5' // 通过npm安装
import md5 from 'blueimp-md5' // 通过npm安装
class Auth {
// 认证信息
constructor (bucket, region, TmpSecretId, TmpSecretKey, XCosSecurityToken, ExpiredTime) {
this.bucket = bucket
this.region = region
this.TmpSecretId = TmpSecretId
this.TmpSecretKey = TmpSecretKey
this.XCosSecurityToken = XCosSecurityToken
this.ExpiredTime = ExpiredTime
}
}
function formatFileName (fileName, dirName) {
// 文件命名规则:业务名+ '/' + md5(文件名+时间戳).文件扩展名
let dotIndex = fileName.lastIndexOf('.')
let baseName = fileName.substring(0, dotIndex) // 获取文件基础名
let extensionName = fileName.substring(dotIndex + 1) // 获取文件扩展名
let timestamp = new Date().getTime() // 获取当前时间戳,以毫秒为单位
let result = dirName + '/'
上传文件到腾讯云COS
最新推荐文章于 2024-04-21 15:36:53 发布