base64转为file
base64ImgtoFile (dataurl, filename = 'file') {
const arr = dataurl.split(',')
const mime = arr[0].match(/:(.*?);/)[1]
const suffix = mime.split('/')[1]
const bstr = atob(arr[1])
let n = bstr.length
const u8arr = new Uint8Array(n)
while (n--) {
u8arr[n] = bstr.charCodeAt(n)
}
return new File([u8arr], `${filename}.${suffix}`, {
type: mime
})
},
arr.map(item=>{
// console.log('-----item',item)
const imageUrl = "data:image/jpeg;base64," +item;
var a1={}
var a2=''
a1 = this.base64ImgtoFile(imageUrl) // 得到File对象
a2 = window.webkitURL.createObjectURL(a1) || window.URL.createObjectURL(a1) // imgUrl图片网络路径
console.log('a1',a1)
console.log('a2',a2)
this.filesData.push(a1)
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27