const COSSDK = require('cos-nodejs-sdk-v5'); // 该模块已经更新到最新
const r = await Txyun.uploadFile({
Bucket: opts.Bucket || incfg.Bucket,
Region: opts.Region || incfg.Region,
Key: fileName,
FilePath: `${filePath}${fileName}`
});
// Txyun.uploadFile 就是该方法
static async uploadFile(params) {
console.log('uploadFile params:', params);
return new Promise((resolve, reject) => {
cos.sliceUploadFile(params, (err, data) => {
console.log('uploadFile err:', err);
console.log('uploadFile data:', data);
// 上传成功后删除本地文件
// fs.unlinkSync(params.FilePath);
if (err) {
reject({ status: 202, error: err });
} else {
resolve({ status: 200, data });
}
});
});
}
// 数据正常返回了,但是上传后的文件是0kb
{ Location: 'resource-1252108727.cos.ap-guangzhou.myqcloud.com/gxkt/test/1543221647710.mp3',
ETag: '"d41d8cd98f00b204e9800998ecf8427e"',
statusCode: 200,
headers:
{ 'content-length': '0',
connection: 'close',
date: 'Mon, 26 Nov 2018 08:40:47 GMT',
etag: '"d41d8cd98f00b204e9800998ecf8427e"',
server: 'tencent-cos',
'x-cos-request-id': 'NWJmYmIxOGZfOTcxYzBiMDlfNWQ1Zl8xMWI2YTg=' } }
相似问题