Skip to content

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

ParameterDescription
AuthorizationBearer Token

Request Parameters

ParameterTypeRequiredDescription
filesfileYesFile (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 NameTypeDescription
idnumberFile ID
filenamestringFile name
urlstringFile access URL
sizenumberFile size (bytes)
mimeTypestringMIME type
createdAtstringUpload time

Error Responses

HTTP Status CodeDescription
401Not logged in or token invalid
413File too large
415Unsupported file type
500Server 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