Upload API

Last updated


This page describes the request format, filename rule, and responses of POST /upload/{path}.

Request


ItemValue
MethodPOST
Path/upload/{path}, where {path} is the target folder under storage/image/upload/; may contain / and is created recursively
Formatmultipart/form-data
File fieldfilepath (single file)
Size limitNone in the app; client_max_body_size 100M through Nginx

Supported Types


Decided by the MIME type the client sends:
MIMEStored extension
image/jpg, image/jpeg.jpg
image/png.png
image/webp.webp
image/svg+xml.svg
application/pdf.pdf

Filename


{16 random alphanumerics}_{millisecond timestamp}.{ext}, e.g. ERftP1gTS7WCTeJ8_1744080848530.jpg. The original filename is not kept.

Responses


StatusTypeBody
201JSON{ success: 1, filename, type, size, src }
400Text請至少規劃一個資料夾位置 (empty {path})
400Text僅支持 jpg / png / webp / svg / pdf
400Textmulter error message (e.g. "Unexpected field" when the field is not filepath)
500Text檔案不存在或上傳失敗 (no file in the request)

src depends on NODE_ENV: development gives http://localhost:8080/c/img/{path}/{filename}, otherwise https://{DOMAIN}/c/img/{path}/{filename}.

Example


  1. curl -fsS -X POST \
  2. -F "filepath=@./photo.png" \
  3. http://localhost:8080/upload/products/2025 \
  4. || echo "upload failed"
中文