Files
tk-mini-program/components/picturesVideosMessages.js
pengxiaolong 7116e57fc3 优化
2025-07-21 22:10:59 +08:00

32 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// let COS = require('cos-wx-sdk-v5')
import COS from 'cos-wx-sdk-v5'
// const COS = require('./lib/cos-wx-sdk-v5.min.js'); // 上线时使用压缩包
const cos = new COS({
SecretId: "AKID4KPIyQgjjnkWJzSnwtfHj281tcBZo28v", // 推荐使用环境变量获取;用户的 SecretId建议使用子账号密钥授权遵循最小权限指引降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
SecretKey: "kQvMjuscBWgfSCqeHiGfx3vc7PUP7ctx", // 推荐使用环境变量获取;用户的 SecretKey建议使用子账号密钥授权遵循最小权限指引降低使用风险。子账号密钥获取可参考https://cloud.tencent.com/document/product/598/37140
});
const picturesVideosMessages = function(file) {
return new Promise((resolve, reject) => {
cos.uploadFile({
Bucket: 'vv-1317974657', // 填入您自己的存储桶,必须字段
Region: 'ap-shanghai', // 存储桶所在地域,例如 ap-beijing必须字段
Key: "sources/" + file.name, // 存储在桶里的对象键例如1.jpga/b/test.txt必须字段文件名
FilePath: file.path, // 必须
FileSize: "", // v1.4.3之前的版本必须v1.4.3及以后的版本非必须
SliceSize: 1024 * 1024 * 2, // 触发分块上传的阈值超过2MB使用分块上传非必须按需调整最小支持1MB
// 支持自定义 headers 非必须
Headers: {
'x-cos-meta-test': 123
},
}, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data.Location);
}
});
});
}
export default picturesVideosMessages