TinyFile 文件
类型定义
TinyFile
类型定义
export type TinyFile = {
filepath: string;
filename: string;
mimetype: string;
size: number;
};
字段说明
字段 | 类型 | 必选 | 描述 |
---|---|---|---|
filepath | string | 是 | 文件的完整路径(如 "/uploads/image.jpg" )。 |
filename | string | 是 | 文件的名称(如 "image.jpg" )。 |
mimetype | string | 是 | 文件的 MIME 类型(如 "image/jpeg" 或 "application/pdf" )。 |
size | number | 是 | 文件的大小(以字节为单位,如 1024 表示 1KB)。 |
示例
图片文件
const imageFile: TinyFile = {
filepath: "/uploads/2023/photo.jpg",
filename: "photo.jpg",
mimetype: "image/jpeg",
size: 2048, // 2KB
};
PDF 文件
const pdfFile: TinyFile = {
filepath: "/documents/report.pdf",
filename: "report.pdf",
mimetype: "application/pdf",
size: 512000, // 500KB
};
文本文件
const textFile: TinyFile = {
filepath: "/notes/readme.txt",
filename: "readme.txt",
mimetype: "text/plain",
size: 1024, // 1KB
};
注意事项
filepath
和filename
的区别filepath
包含完整路径,filename
仅为文件名(含扩展名)。
mimetype
的格式- 需符合标准 MIME 类型(如
image/png
、application/json
)。
- 需符合标准 MIME 类型(如
size
的单位- 始终以字节(Byte)为单位,计算大小时需注意单位转换(如 1MB = 1024KB)。