rendezvous/www/lib/blob-to-b64.js
2023-06-21 15:33:47 +00:00

30 lines
628 B
JavaScript

//
// 2023.01.10
//
export default async function blobToB64(b,type){
// https://ionic.io/blog/converting-a-base64-string-to-a-blob-in-javascript
// https://github.com/jeremyBanks/b64-to-blob/blob/master/b64toBlob.js
//
// upg: to b64url and/or data urls?
// size limit?
//console.log({b,type}) // upg: type to override blob type or?
let p = new Promise((res, rej) => {
const r = new FileReader
r.onerror = rej
r.onload = e=>{
const {result} = r
const x = result.split(',') // and/or? 'data:image/jpeg;base64'
res(x[1])
}
r.readAsDataURL(b)
})
let rr = await p
return p
}//func