Skip to content

File 文件模块

文件相关操作方法。

getFileUrl(file)

根据文件获取可预览的文件路径。

参数

参数类型必填说明
fileFile文件对象

返回值

String - 可预览的 URL

示例

js
const input = document.querySelector('input[type="file"]')
input.onchange = (e) => {
  const url = Qilin.File.getFileUrl(e.target.files[0])
  console.log(url)    // blob:http://xxx
}

getFileBase64(file)

将 File 对象转为 Base64 格式的字符串。

参数

参数类型必填说明
fileFile文件对象

返回值

Promise<String> - Base64 字符串

示例

js
const input = document.querySelector('input[type="file"]')
input.onchange = async (e) => {
  const base64 = await Qilin.File.getFileBase64(e.target.files[0])
  console.log(base64)    // data:image/png;base64,...
}

getBase64File(base64String, fileName)

将 Base64 格式字符串转换为 File 对象。

参数

参数类型必填说明
base64StringStringBase64 格式字符串
fileNameString转换后的文件名(包含后缀)

返回值

File - File 对象

示例

js
const base64 = 'data:image/png;base64,iVBORw0KGgo...'
const file = Qilin.File.getBase64File(base64, 'image.png')
console.log(file)    // File { name: 'image.png', type: 'image/png', ... }

基于 ISC 许可发布