文件转为Base64
... 2025-7-10 小于 1 分钟
# 文件转为 Base64
// File类型:File {uid: 1650523257533, name: '1.png', lastModified: 1650504748611, lastModifiedDate: Thu Apr 21 2022 09:32:28 GMT+0800 (中国标准时间), webkitRelativePath: '', …}
// Blob类型:Blob {size: 338, type: 'image/png'}
// File 文件 转换为 Blob 类型
let blob = new Blob([file.raw], { type: file.raw.type })
// Blob转换为URL blob:http://localhost:8080/7141182d-b488-45e6-b667-fe639767ef0b
let PDF_URL = URL.createObjectURL(blob)
// File 文件 转换为base64
var reader = new FileReader()
reader.readAsDataURL(file.raw)
// 获取base64
reader.onload = function () {
console.log(reader.result)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15