阿里雲OSS 服務端簽名後直傳之分片上傳(結合element-ui的upload組件)

分片上傳(結合element-ui的upload組件實現自定義上傳)html

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('視頻上傳失敗')
        }
    }
}

 

官方文檔: 傳送門element-ui

相關文章
相關標籤/搜索