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


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

 

官方文檔: 傳送門

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM