分片上传(结合element-ui的upload组件实现自定义上传)
async uploadFree(content){ let data = await this.getOssToken(); //后台返回的OSS秘钥等等 let client = new OSS({ region: data.region, accessKeyId: data.AccessKeyId, accessKeySecret: data.AccessKeySecret, stsToken: data.SecurityToken, bucket: data.bucketName }); try { let result = await client.multipartUpload(content.file.name, content.file, { progress: async function (p) {//这是上传进度条 content.onProgress({percent: parseInt(p * 100)+'%', returnValue: true }); } }); return (content.file['response'] = [result].map(curr =>{//on-change回调的参数 return { code: curr.res.status, name: content.file.name, data: curr.res.requestUrls[0].split('?')[0] } })[0]); } catch (e) { console.log(e) if (e.code === 'ConnectionTimeoutError') { content.onError('视频上传超时') throw "视频上传超时!"; }else{ content.onError('视频上传失败') } } }
官方文档: 传送门