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 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| function base64ToBlob({ b64data = '', contentType = '', sliceSize = 512 } = {}) { return new Promise((resolve, reject) => { let byteCharacters = atob(b64data); let byteArrays = []; for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { let slice = byteCharacters.slice(offset, offset + sliceSize); let byteNumbers = []; for (let i = 0; i < slice.length; i++) { byteNumbers.push(slice.charCodeAt(i)); } byteArrays.push(new Uint8Array(byteNumbers)); } let result = new Blob(byteArrays, { type: contentType }) result = Object.assign(result, { preview: URL.createObjectURL(result), name: `XXX.png` }); resolve(result) }) } var base64 = base64.split(',')[1] base64ToBlob({ b64data: base64, contentType: 'image/png' }).then(res => { console.log('blob', res) })
|
评论加载中