File Upload
Interface for uploading files.
Upload File
Upload single or multiple files.
Interface Information
- Endpoint:
POST /api/upload - Authentication: Required
- Content-Type:
multipart/form-data
Request Headers
| Parameter | Description |
|---|---|
| Authorization | Bearer Token |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| files | file | Yes | File (supports multiple) |
Request Examples
bash
# Upload single file
curl -X POST http://localhost:3000/api/upload \
-H "Authorization: Bearer your-jwt-token" \
-F "files=@image.jpg"
# Upload multiple files
curl -X POST http://localhost:3000/api/upload \
-H "Authorization: Bearer your-jwt-token" \
-F "files=@image1.jpg" \
-F "files=@image2.png"Response Example
json
{
"success": true,
"data": [
{
"id": 1,
"filename": "image.jpg",
"url": "https://example.com/uploads/image.jpg",
"size": 102400,
"mimeType": "image/jpeg",
"createdAt": "2024-01-15T10:00:00.000Z"
},
{
"id": 2,
"filename": "image2.png",
"url": "https://example.com/uploads/image2.png",
"size": 204800,
"mimeType": "image/png",
"createdAt": "2024-01-15T10:00:00.000Z"
}
]
}Response Fields
| Field Name | Type | Description |
|---|---|---|
| id | number | File ID |
| filename | string | File name |
| url | string | File access URL |
| size | number | File size (bytes) |
| mimeType | string | MIME type |
| createdAt | string | Upload time |
Error Responses
| HTTP Status Code | Description |
|---|---|
| 401 | Not logged in or token invalid |
| 413 | File too large |
| 415 | Unsupported file type |
| 500 | Server error |
File Limits
- Single file maximum 10MB
- Supported image formats: jpg, jpeg, png, gif, webp
- Supported document formats: pdf, doc, docx, xls, xlsx
- Supported archive formats: zip, rar
Storage Location
Uploaded files are stored by default in the /public/uploads directory. Production environments should use cloud storage (such as Alibaba Cloud OSS, Tencent Cloud COS).
Security Notes
- File type and size are validated before upload
- Filenames are automatically renamed to prevent conflicts
- Sensitive file types are automatically filtered