本地bloburl轉化file格式createObjectURL創建的圖片url地址轉化文件地址file進行上傳


圖片二進制地址blob轉化文件file格式createObjectURL創建的圖片url地址轉化文件地址file進行上傳

主要代碼

//blob文件轉化
function httpRequest(src){
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('GET',src,true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
let myBlob = this.response;
let files = new window.File([myBlob], myBlob.type, {type:myBlob.type}) // myBlob.type 自定義文件名
resolve(files)
}else{
reject(false)
}
};
xhr.send();
})
}

自定義函數獲取使用

async beginUploadImageIfNeed() {

file = await httpRequest(bloburl) //bloburl 格式 blob:null/73e6954e-58ee-4165-870b-03614f9e3b5f

}

fild顯示結果


轉載


免責聲明!

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



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