Skip to content

fileToBase64

将文件转换为 base64 字符串

基础用法

参数名参数类型是否必传默认值参数说明
fileFile-图片文件
maxSizeMBnumber20图片文件

返回

Promise<string> base64 字符串,转换失败或文件过大返回空字符串

ts
import { fileToBase64 } from '@lichang666/utils'
import ExampleFile from '@/assets/example.png'
const base64Str = await fileToBase64(ExampleFile)
if (base64Str) {
  console.log(base64Str)
} else {
  console.log('转换失败或文件过大')
}