腾讯云上传使用
1:安装插件
cos-js-sdk-v5 yarn add cos-js-sdk-v5
2:导入
import Cos from 'cos-js-sdk-v5'
3:实例化
let cos = new Cos({
SecretId: 'COS_SECRETID', // 身份识别 ID
SecretKey: 'COS_SECRETKEY', // 身份密钥
});
4:使用
cos.putObject({
Bucket: 'dhf481229-1305249343', /* 存储桶: */
Region: 'ap-guangzhou', /* 存储桶所在地域,必须字段 */
Key: uid+'', /* 必须是字符串 */
StorageClass: 'STANDARD', // 固定值
Body: 文件对象, // 上传文件对象
onProgress: (progressData)=> {
// 上传进度
console.log(JSON.stringify(progressData));
}
}, (err, data)=> {
// 上传成功或者失败的回调
console.log(err || data);
});