JS 将 base64编码的图片转化为图片文件

需求:将string 类型的base64编码图片转化成File类型的图片文件,用于文件上传

function dataURLtoFile(dataurl, filename = 'file') {
  let arr = dataurl.split(',')
  let mime = arr[0].match(/:(.*?);/)[1]
  let suffix = mime.split('/')[1]
  let bstr = atob(arr[1])
  let n = bstr.length
  let u8arr = new Uint8Array(n)
  while (n--) {
    u8arr[n] = bstr.charCodeAt(n)
  }
  return new File([u8arr], `${filename}.${suffix}`, {
    type: mime
  })
}
 // base64编码的图片
var base64Img = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wgARCAF+AoADASIAAhEBAxEB/8QAGwABAAIDAQEAAAAAAAAAAAAAAAIFAwQGAQf/xAAaAQEAAwEBAQAAAAAAAAAAAAAAAgMEAQUG/9oADAMBAAIQAxAAAAHvwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHjj1r4Yy3la5KyaOfsc7z2UTz3oAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAeHrzUj3b06TVya7Kv39+E+dzdP73nNOld5y+Dr487zG/vV8e223x23bDp2ptasnolwAAAAAAAAAAAAAAAAAAAAAAAAAAAAeDxz9VmxT5b3Hs0rMuzSRTjJFzk0HUkXOyRCqtUZcvdZ6KjV1vtBe7sMhZAAAAAAAAAAAAAAAAAAAAAAAAAAADzz2qhLU1YX2DfKUVuWSLqUdbXnDbhiyyRZRCXmPvNudZm53dQ9qlKHp2h3t2hp1dcrLPfg9E4gAAAAAAAAAAAAAAAAAAAAA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Z9h/L9WdIwnDkEUFWZzHzxaBHWBu17/ysA4bQoC1tmK8ULeA0TXvDqeSVS46qwQ0y7FRZSraw1rMrRkpZwtCCvjLR7YRWomq83nzKDQm+3+QPvEftXUhtXzjq6S7CI22UWlWNYs04ZhrYJrOLy63Wi/SEEu9lVbYsl3pbN8kqwdE2/wDqlxP/2Q==';
// 转成图片文件
var imgFile = dataURLtoFile(base64Img); 

## 如果想要预览转出来的图片可以:
const fileReader = new FileReader();  // 创建一个 fileReader
fileReader.readAsDataURL(imgFile); // 将生成的图片文件读到 fileReader中
const img = new Image();
img.src = fileReader.result; // 将 fileReader.result 设置为 图片的 src
document.body.appendChild(img);

你可能感兴趣的:(JS 将 base64编码的图片转化为图片文件)