32 lines
917 B
Markdown
32 lines
917 B
Markdown
# fileUpload.ts
|
||
|
||
**路径**:`src/api/fileUpload.ts`
|
||
|
||
## 功能用途
|
||
|
||
文件上传接口封装,用于头像等文件上传场景。先调用 upload 上传文件,获取返回的 URL 后可供 setSelfHeaderImg 设置头像。
|
||
|
||
## 导出
|
||
|
||
| 导出 | 类型 | 说明 |
|
||
|------|------|------|
|
||
| `upload(file, authHeaders)` | `Promise<UploadResponse>` | POST /fileUploadAndDownload/upload,multipart/form-data |
|
||
| `ExaFileUploadAndDownload` | interface | 上传返回的 data.file 结构,含 url、key、name 等 |
|
||
|
||
## 使用方式
|
||
|
||
```typescript
|
||
import { upload } from '@/api/fileUpload'
|
||
import { setSelfHeaderImg } from '@/api/user'
|
||
|
||
const res = await upload(file, userStore.getAuthHeaders())
|
||
const fileUrl = res.data?.file?.url
|
||
if (fileUrl) {
|
||
await setSelfHeaderImg(authHeaders, { headerImg: fileUrl })
|
||
}
|
||
```
|
||
|
||
## 扩展方式
|
||
|
||
- 支持其他上传场景:可复用 upload,或扩展分片、断点续传等
|