最近在做阿里云的oss文件上传功能
import Oss from 'ali-oss';
const client = new Oss({
region: ossProps.value.region,
accessKeyId: ossProps.value.accessKeyId,
accessKeySecret: ossProps.value.accessKeySecret,
bucket: ossProps.value.bucket,
});
将Oss配置好后,调用oss实例的分片上传方法
client.multipartUpload(filePath, file, {
progress(p) {
// 上传过程中关闭窗口,取消上传
if (closedUpload.value) {
cancelClientUpload();
};
// percent.value = (p * 100).toFixed(2) - 0;
percent.value = (p).toFixed(2) - 0;
}
}).then((res) => {
}).catch(err => {
console.log('err', err);
})
问题现象
在上传文件时触发client.multipartUpload就会出现报错:TypeError: Cannot read properties of null (reading 'Bucket')
解决方案
有部分网友说是版本问题,经过升级版本等操作,发现还是有这个问题
最后发现项目中使用了mockjs库,在发送responseType: arraybuffer 时,自己封装了一次,把原生的xmlHttpRequest中的responseType变成了 '',导致了后续无法解析。