Initial commit: ERP system with advance verification fixes
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// COS配置 - 香港区域
|
||||
const COS = require('cos-nodejs-sdk-v5');
|
||||
|
||||
const cosConfig = {
|
||||
SecretId: process.env.TENCENT_SECRET_ID || '',
|
||||
SecretKey: process.env.TENCENT_SECRET_KEY || '',
|
||||
Bucket: 'qingyuan-erp-files-1257307187',
|
||||
Region: 'ap-hongkong'
|
||||
};
|
||||
|
||||
const cos = new COS(cosConfig);
|
||||
const imageFormats = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'svg'];
|
||||
|
||||
// 上传到COS
|
||||
function uploadToCOS(buffer, filename, mimetype) {
|
||||
return new Promise((resolve, reject) => {
|
||||
cos.putObject({
|
||||
Bucket: cosConfig.Bucket,
|
||||
Region: cosConfig.Region,
|
||||
Key: filename,
|
||||
Body: buffer,
|
||||
ContentType: mimetype
|
||||
}, (err, data) => {
|
||||
if (err) reject(err);
|
||||
else {
|
||||
const url = 'https://' + cosConfig.Bucket + '.cos.' + cosConfig.Region + '.myqcloud.com/' + filename;
|
||||
resolve({ url, filename });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = { cos, cosConfig, uploadToCOS, imageFormats };
|
||||
Reference in New Issue
Block a user