xtraderClient/docs/api/fileUpload.md
2026-03-22 17:47:44 +08:00

32 lines
917 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# fileUpload.ts
**路径**`src/api/fileUpload.ts`
## 功能用途
文件上传接口封装,用于头像等文件上传场景。先调用 upload 上传文件,获取返回的 URL 后可供 setSelfHeaderImg 设置头像。
## 导出
| 导出 | 类型 | 说明 |
|------|------|------|
| `upload(file, authHeaders)` | `Promise<UploadResponse>` | POST /fileUploadAndDownload/uploadmultipart/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或扩展分片、断点续传等