本地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