Skip to content

文件处理

框架提供了一些常用的处理文件方法可以直接使用。

getFileName

根据文件路径获取文件名。

参数说明类型默认值
path文件路径string
ts
import { getFileName } from 'liv-web';

const path = '/server/file/test.png';
const fileName = getFileName(path);
console.log(fileName); // 输出test.png

getMd5ByFile2.1.0

通过文件获取唯一标识md5

参数说明类型默认值
file文件对象File
ts
import { getMd5ByFile } from 'liv-web';

const file = new File([], 'test.txt');
console.log(getMd5ByFile(file)); // 文件的MD5值

downloadFileByUrl2.1.1

通过url地址下载文件。

参数说明类型默认值
url需要下载文件的url地址string
ts
import { downloadFileByUrl } from 'liv-web';

downloadFileByUrl('https://www.liv-web.com/download/test.txt');