文件处理
框架提供了一些常用的处理文件方法可以直接使用。
getFileName
根据文件路径获取文件名。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| path | 文件路径 | string | — |
ts
import { getFileName } from 'liv-web';
const path = '/server/file/test.png';
const fileName = getFileName(path);
console.log(fileName); // 输出test.pnggetMd5ByFile2.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');