> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sinancode.com/llms.txt
> Use this file to discover all available pages before exploring further.

# URL アップロード

> リモート URL からファイルをダウンロードしてストレージにアップロードします。

URL からファイルをフェッチしてクラウドストレージにアップロードします。

**主な特徴:**

* **URL から直接アップロード** - ファイルをダウンロードせずに URL を指定するだけ
* **自動フェッチ** - システムが URL からファイルを自動取得


## OpenAPI

````yaml /ja/files-openapi.json POST /api/upload/url
openapi: 3.0.3
info:
  title: ファイルアップロード API
  description: Base64、multipart/form-data、またはリモート URL 経由でファイルをアップロードします。Cloudflare R2 を使用。
  version: 1.0.0
  contact:
    name: SinanCode
    url: https://sinancode.com
servers:
  - url: https://files-api.sinancode.com
    description: 本番サーバー
security:
  - bearerAuth: []
tags:
  - name: アップロード
    description: ファイルアップロード操作
paths:
  /api/upload/url:
    post:
      tags:
        - アップロード
      summary: リモート URL からファイルをアップロード
      description: リモート URL からファイルをダウンロードしてストレージにアップロードします。
      operationId: uploadUrl
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UrlUploadRequest'
            example:
              url: https://example.com/image.png
      responses:
        '201':
          $ref: '#/components/responses/UploadSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '500':
          $ref: '#/components/responses/InternalError'
components:
  schemas:
    UrlUploadRequest:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          format: uri
          description: ダウンロードしてアップロードするファイルのリモート URL
          example: https://example.com/image.png
        filename:
          type: string
          description: オプションのカスタムファイル名（拡張子付き）
          example: my-image.png
    UploadSuccessResponse:
      type: object
      required:
        - url
        - cn_url
        - key
        - md5
        - size
        - content_type
        - expires_at
      properties:
        url:
          type: string
          format: uri
          description: アップロードされたファイルにアクセスするための公開 URL（グローバル）
          example: https://upload-tmp.sinancode.com/uploads/user123/abc123def456.png
        cn_url:
          type: string
          format: uri
          description: アップロードされたファイルにアクセスするための公開 URL（中国）
          example: >-
            https://beijing-user-upload-tmp.tos-cn-beijing.volces.com/uploads/user123/abc123def456.png
        key:
          type: string
          description: アップロードされたファイルのストレージキー
          example: uploads/user123/abc123def456.png
        md5:
          type: string
          description: ファイル内容のハッシュ（SHA-256 切り捨て）
          example: d41d8cd98f00b204e9800998ecf8427e
        size:
          type: integer
          description: ファイルサイズ（バイト単位）
          example: 12345
        content_type:
          type: string
          description: ファイルの MIME タイプ
          example: image/png
        expires_at:
          type: string
          format: date-time
          description: ファイルの有効期限（ISO 8601）
          example: '2024-01-17T00:00:00.000Z'
    ErrorResponse:
      type: object
      required:
        - message
        - error_code
      properties:
        message:
          type: string
          description: 人間が読めるエラーメッセージ
          example: Invalid file format
        error_code:
          type: string
          description: 機械可読エラーコード
          example: UPLOAD.INVALID_FILE
  responses:
    UploadSuccess:
      description: ファイルが正常にアップロードされました
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UploadSuccessResponse'
    BadRequest:
      description: 無効なリクエストパラメータ
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            message: 'Missing required field: data'
            error_code: UPLOAD.INVALID_FILE
    Unauthorized:
      description: 認証トークンがないか無効です
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            message: Missing authorization token
            error_code: AUTH.MISSING_TOKEN
    PayloadTooLarge:
      description: ファイルサイズが最大制限（50MB）を超えています
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            message: File size exceeds maximum limit of 50MB
            error_code: UPLOAD.FILE_TOO_LARGE
    InternalError:
      description: 内部サーバーエラー
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            message: Internal server error
            error_code: INTERNAL_ERROR
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: api.sinancode.com から取得した認証トークン

````