본문 바로가기

메뉴

  • 미디어
  • 요금제
  • 개발자 문서
  • 언어: 한국어

    회색으로 표시된 언어로는 이 페이지가 제공되지 않습니다.

    • English
    • Español
    • Português
    • Français
    • Deutsch
    • Italiano
    • Nederlands
    • Polski
    • 日本語
    • 한국어
    • Bahasa Indonesia
    • Tiếng Việt
    • Türkçe
    • العربية
    • ไทย
    • Български
    • Català
    • Hrvatski
    • Eesti
    • Magyar
    • Latviešu
    • Lietuvių
    • Srpski
    • Slovenčina
    • Slovenščina
    • Українська
    • Čeština
    • Română
    • Svenska
    • Dansk
    • Norsk bokmål
    • Suomi
    • עברית
    • हिन्दी
    • Tagalog
    • Bahasa Melayu
    • Ελληνικά
    • 简体中文
    • 繁體中文

파일 업로드

파일은 스토리지로 바로 전송됩니다. 5GB까지는 한 번에 보내거나, 파트로 나눠 보낼 수 있습니다. API는 업로드 링크를 발급하고, 작업에서 파일을 사용하기 전에 파일을 검사합니다.

이 페이지의 내용

업로드 과정

  1. 시작: POST /v1/uploads로 업로드를 시작합니다. 파일을 사용할 오퍼레이션과 파일 이름, 크기를 보냅니다.
  2. 파일 전송: 발급받은 링크로 PUT 요청을 보내 파일을 전송합니다. 5GB까지는 요청 한 번으로 보내거나, 파트로 나눠 파트마다 각자의 링크로 보냅니다.
  3. 완료: POST /v1/uploads/{id}/complete로 업로드를 완료합니다. 파일 검사가 진행되고, 작업에서 파일 ID를 사용할 수 있게 됩니다.

5GB 이하 파일은 요청 한 번으로 보냅니다. 그보다 큰 파일과 파트 분할을 요청한 파일은 파트로 나눠 보냅니다. 이렇게 하면 전송에 실패한 파트만 다시 보내면 되므로, 업로드가 중단되더라도 처음부터 다시 시작할 필요가 없습니다.

업로드 시작하기

호출 한 번으로 업로드를 최대 50개까지 시작할 수 있습니다. 허용되는 파일 형식과 크기는 오퍼레이션이 정하며, 각 파일은 데이터를 보내기 전인 이 시점에 그 기준으로 검사됩니다.

curl -X POST https://api.filesokay.com/v1/uploads \
  -H "Authorization: Bearer $FILESOKAY_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "operation": "video.compress",
    "files": [
      {
        "name": "lecture.mp4",
        "size": 12417467,
        "type": "video/mp4"
      }
    ]
  }'
const res = await fetch("https://api.filesokay.com/v1/uploads", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": crypto.randomUUID(),
  },
  body: JSON.stringify({
    operation: "video.compress",
    files: [
      {
        name: "lecture.mp4",
        size: 12417467,
        type: "video/mp4"
      }
    ]
  }),
});
const uploads = await res.json();
import os
import uuid

import requests

res = requests.post(
    "https://api.filesokay.com/v1/uploads",
    headers={
        "Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
      "operation": "video.compress",
      "files": [
        {
          "name": "lecture.mp4",
          "size": 12417467,
          "type": "video/mp4"
        }
      ]
    },
)
uploads = res.json()
응답
{
  "files": [
    {
      "id": "file_3cf0737aefa34b89b7b4443c9467d60c",
      "name": "lecture.mp4",
      "size": 12417467,
      "part_size": 12417467,
      "part_count": 1,
      "parts": [
        {
          "number": 1,
          "url": "https://…"
        }
      ],
      "links_expire_at": "2026-12-03T10:22:53Z",
      "delete_at": "2026-12-10T09:22:52Z"
    }
  ]
}
  • 5GB 이하 파일에는 파일 전체를 보낼 링크가 하나 제공됩니다. 이때 part_count는 1이고 part_size는 파일 크기와 같습니다. 크기와 상관없이 파트로 나눠 보내려면 "multipart": true를 보내세요.
  • 파트로 나눌 때 part_size는 마지막 파트를 제외한 모든 파트의 크기입니다. 최소 16MiB이며, 파일 전체가 10,000개 파트 안에 들어갈 만큼 큽니다.
  • parts에는 처음 20개 파트의 링크가 들어 있습니다. 각 링크는 1시간 동안, 즉 links_expire_at까지 유효합니다.
  • delete_at은 업로드를 완료하지 않았을 때 업로드가 삭제되는 시각으로, 시작 후 7일입니다.

추가할 수 없는 파일은 file_too_large, unsupported_type, empty_file 중 하나로 거부됩니다. 오류의 files 필드에는 문제가 있는 파일이 요청에서의 위치와 함께 나열됩니다.

파트 전송하기

링크가 하나라면 PUT 한 번으로 파일 전체를 보냅니다. 파트로 나눌 때는 파일의 처음 part_size바이트를 파트 1로, 다음 구간을 파트 2로 보내는 식으로 이어 갑니다. 파트는 순서와 상관없이 보내도 되고, 여러 개를 동시에 보내도 됩니다. 각 링크에 권한이 담겨 있으므로 API 키 없이 보내세요.

파트가 20개를 넘는 파일은 링크가 더 필요합니다. POST /v1/uploads/{id}/parts로 한 번에 최대 100개까지 요청하고, 링크가 만료되면 같은 방법으로 다시 요청하세요. 아래 함수는 크기와 상관없이 파일을 파트로 나눠 업로드합니다.

# 파일을 part_size바이트(여기서는 16777216) 단위 파트로 나눕니다: part-aa, part-ab, …
split -b 16777216 keynote.mp4 part-

# 각 파트를 자기 링크로 순서대로 보냅니다: part-aa는 파트 1로, part-ab는 파트 2로, …
curl -X PUT --upload-file part-aa "$PART_1_URL"
curl -X PUT --upload-file part-ab "$PART_2_URL"

# 처음 20개 링크를 다 쓰면 다음 링크를 한 번에 최대 100개까지 요청합니다.
curl https://api.filesokay.com/v1/uploads/file_20f80f7404ff41858dc0a0544f059576/parts \
  -H "Authorization: Bearer $FILESOKAY_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "part_numbers": [21, 22, 23] }'
import fs from "node:fs/promises";
import path from "node:path";

const API = "https://api.filesokay.com/v1";

async function post(route, body) {
  const res = await fetch(API + route, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
      "Content-Type": "application/json",
    },
    body: body && JSON.stringify(body),
  });
  const data = await res.json();
  if (!res.ok) throw new Error(`${data.code}: ${data.detail}`);
  return data;
}

// 크기와 상관없이 파일을 오퍼레이션용으로 업로드하고, 검사 결과와 함께 반환합니다.
async function uploadFile(filePath, operation) {
  const handle = await fs.open(filePath);
  try {
    const { size } = await handle.stat();
    const { files: [upload] } = await post("/uploads", {
      operation,
      files: [{ name: path.basename(filePath), size }],
      multipart: true,
    });

    // 링크는 1시간 동안 유효합니다. 마지막 링크를 다 썼거나 50분이 지나면 다음 100개를 요청합니다.
    let links = new Map(upload.parts.map((part) => [part.number, part.url]));
    let linksAt = Date.now();
    for (let number = 1; number <= upload.part_count; number++) {
      if (!links.has(number) || Date.now() - linksAt > 50 * 60 * 1000) {
        const last = Math.min(number + 99, upload.part_count);
        const part_numbers = Array.from({ length: last - number + 1 }, (_, i) => number + i);
        const more = await post(`/uploads/${upload.id}/parts`, { part_numbers });
        links = new Map(more.parts.map((part) => [part.number, part.url]));
        linksAt = Date.now();
      }
      const start = (number - 1) * upload.part_size;
      const bytes = Buffer.alloc(Math.min(upload.part_size, size - start));
      await handle.read(bytes, 0, bytes.length, start);
      const res = await fetch(links.get(number), { method: "PUT", body: bytes });
      if (!res.ok) throw new Error(`Part ${number} failed: ${res.status}`);
    }
    return await post(`/uploads/${upload.id}/complete`);
  } finally {
    await handle.close();
  }
}

const file = await uploadFile("lecture.mp4", "video.compress");
console.log(file.id, file.check.state);
import os
import time

import requests

API = "https://api.filesokay.com/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}"}


def post(route, body=None):
    res = requests.post(API + route, json=body, headers=HEADERS)
    data = res.json()
    if not res.ok:
        raise RuntimeError(f"{data['code']}: {data['detail']}")
    return data


def upload_file(file_path, operation):
    """크기와 상관없이 파일을 오퍼레이션용으로 업로드하고, 검사 결과와 함께 반환합니다."""
    upload = post("/uploads", {
        "operation": operation,
        "files": [{"name": os.path.basename(file_path), "size": os.path.getsize(file_path)}],
        "multipart": True,
    })["files"][0]

    # 링크는 1시간 동안 유효합니다. 마지막 링크를 다 썼거나 50분이 지나면 다음 100개를 요청합니다.
    links = {part["number"]: part["url"] for part in upload["parts"]}
    links_at = time.monotonic()
    with open(file_path, "rb") as f:
        for number in range(1, upload["part_count"] + 1):
            if number not in links or time.monotonic() - links_at > 50 * 60:
                last = min(number + 99, upload["part_count"])
                more = post(f"/uploads/{upload['id']}/parts",
                            {"part_numbers": list(range(number, last + 1))})
                links = {part["number"]: part["url"] for part in more["parts"]}
                links_at = time.monotonic()
            f.seek((number - 1) * upload["part_size"])
            requests.put(links[number], data=f.read(upload["part_size"])).raise_for_status()
    return post(f"/uploads/{upload['id']}/complete")


file = upload_file("lecture.mp4", "video.compress")
print(file["id"], file["check"]["state"])

업로드 완료하기

업로드를 완료하면 파트를 하나로 합치고 파일 내용을 검사합니다. 다시 호출해도 같은 응답을 받습니다.

curl -X POST https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c/complete \
  -H "Authorization: Bearer $FILESOKAY_KEY"
const res = await fetch("https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c/complete", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
  },
});
const file = await res.json();
import os

import requests

res = requests.post(
    "https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c/complete",
    headers={
        "Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}",
    },
)
file = res.json()
응답
{
  "id": "file_3cf0737aefa34b89b7b4443c9467d60c",
  "name": "lecture.mp4",
  "operation": "video.compress",
  "state": "uploaded",
  "size": 12417467,
  "created_at": "2026-12-03T09:22:53Z",
  "uploaded_at": "2026-12-03T09:23:02Z",
  "delete_at": "2026-12-04T09:23:02Z",
  "check": {
    "state": "proceed",
    "kind": "video",
    "type": "mp4",
    "facts": {
      "container": "mp4",
      "protection": "none",
      "attachments": [],
      "duration_ms": 20023,
      "frame_count": 600,
      "audio_tracks": [
        {
          "codec": "aac",
          "channels": 1,
          "sample_rate": 44100
        }
      ],
      "video_tracks": [
        {
          "hdr": "none",
          "codec": "h264",
          "width": 1280,
          "chroma": "420",
          "height": 720,
          "profile": "High",
          "rotation": 0,
          "bit_depth": 8,
          "frame_rate": 30,
          "interlaced": false,
          "variable_frame_rate": false
        }
      ],
      "data_end_bytes": 12417467,
      "subtitle_tracks": []
    },
    "facts_complete": true
  }
}

check는 파일 이름과 상관없이 파일의 실제 정체를 알려 줍니다. 파일 종류인 kind, 실제 형식을 담은 type, 검사에서 읽어 낸 정보인 facts(동영상 길이, 코덱 등)가 포함됩니다. state는 다음 중 하나입니다.

상태의미
proceed작업에서 파일을 사용할 수 있습니다.
refusereason에 적힌 이유(파일 손상, 보호된 파일 등)로 어떤 작업에서도 사용할 수 없습니다.
couldnt_read검사에서 파일 전체를 읽지 못했습니다. 그래도 작업에서 사용할 수 있으며, 작업이 파일 전체를 읽습니다.
check_failedFilesOkay 측 문제입니다. 업로드를 다시 완료하면 검사를 다시 실행합니다.
checking검사가 아직 끝나지 않았습니다.

누락된 파트가 있거나 파트 길이가 맞지 않으면 완료 요청이 upload_incomplete로 거부되며, 다시 보내야 할 파트가 함께 표시됩니다.

중단된 업로드 재개하기

GET /v1/uploads/{id}는 스토리지가 이미 받은 파트를 parts_received에 나열합니다. 빠진 파트만 보내고(처음 받은 링크가 만료되었다면 새 링크로), 업로드를 완료하세요.

curl https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c \
  -H "Authorization: Bearer $FILESOKAY_KEY"
const res = await fetch("https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c", {
  headers: {
    Authorization: `Bearer ${process.env.FILESOKAY_KEY}`,
  },
});
const progress = await res.json();
import os

import requests

res = requests.get(
    "https://api.filesokay.com/v1/uploads/file_3cf0737aefa34b89b7b4443c9467d60c",
    headers={
        "Authorization": f"Bearer {os.environ['FILESOKAY_KEY']}",
    },
)
progress = res.json()
응답
{
  "delete_at": "2026-12-10T09:22:52Z",
  "id": "file_3cf0737aefa34b89b7b4443c9467d60c",
  "part_count": 1,
  "part_size": 12417467,
  "parts_received": [
    {
      "number": 1,
      "size": 12417467
    }
  ],
  "size": 12417467,
  "state": "uploading"
}

delete_at 시각이 지나면 업로드가 삭제되고, 이후 호출은 not_found로 응답합니다. 이때는 업로드를 다시 시작하세요. 업로드를 직접 중단하려면 DELETE /v1/uploads/{id}로 취소하세요. 이미 보낸 파트도 함께 폐기됩니다.

업로드 보관 기간

어떤 작업에도 사용되지 않은 완료된 업로드는 완료 후 24시간, 10GiB 이상 파일은 3일이 지나면 삭제됩니다. 작업에서 사용한 뒤에는 작업의 보관 규칙이 적용됩니다. 파일 보관 기간을 참고하세요.