file.js 448 B

1234567891011121314151617
  1. export const base64ToBlob = base64 => {
  2. let arr = base64.split(','),
  3. mime = arr[0].match(/:(.*?);/)[1],
  4. bstr = atob(arr[1]),
  5. n = bstr.length,
  6. u8arr = new Uint8Array(n)
  7. while (n--) {
  8. u8arr[n] = bstr.charCodeAt(n)
  9. }
  10. return new Blob([u8arr], { type: mime })
  11. }
  12. export function convertBlob2File(blob, name) {
  13. return new File([blob], name, {
  14. type: blob.type,
  15. })
  16. }