Skip to content

Instantly share code, notes, and snippets.

@jamessa
Last active March 4, 2025 01:56
Show Gist options
  • Select an option

  • Save jamessa/2021ba5528a119048bbfa51a7a96d1f8 to your computer and use it in GitHub Desktop.

Select an option

Save jamessa/2021ba5528a119048bbfa51a7a96d1f8 to your computer and use it in GitHub Desktop.
OpenAPI schema
openapi: 3.0.0
info:
  title: Saturn API
  version: 1.0.0

paths:
  /api/records/image:
    post:
      summary: 上傳照片
      description: 接收 Base64 編碼的檔案,並存儲至伺服器。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ImageUploadRequest"
      responses:
        200:
          description: 上傳成功的回應
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ImageUploadResponse"
        400:
          description: 無效的請求數據
        500:
          description: 伺服器內部錯誤

components:
  schemas:
    ImageUploadRequest:
      type: object
      properties:
        edge_id:
          type: string
          description: "設備的唯一識別碼 Edge ID。"
        filename:
          type: string
          description: "上傳的檔案名稱,通常包含時間戳記。"
        base64file:
          type: string
          format: byte
          description: "Base64 編碼的檔案內容。"
      required:
        - edge_id
        - filename
        - base64file

    ImageUploadResponse:
      type: object
      properties:
        retcode:
          type: integer
          description: "返回碼,0 表示成功,其他數值可能代表錯誤。"
        msg:
          type: string
          description: "訊息內容,通常用於錯誤或狀態描述。"
        data:
          type: object
          properties:
            files:
              type: array
              items:
                type: string
                format: uri
              description: "檔案的 URL, 可能經過 URL 編碼。"
          required:
            - files
        errors:
          type: array
          items:
            type: string
          description: "錯誤訊息列表, 若無錯誤則為空陣。"
      required:
        - retcode
        - msg
        - data

demo

Screenshot 2025-03-04 at 9 52 51 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment