메인 콘텐츠로 건너뛰기

Tag 기반 버전 조회 규칙

  • 하나의 filename에 대해 optional tag를 붙여 여러 버전을 운영할 수 있습니다.
  • 예시:
    • Items.json (tag 없음)
    • Items.json (tag = v1)
    • Items.json (tag = v2)
조회 시 동작:
  • tag를 지정하면 filename(key) + tag가 정확히 일치하는 객체를 조회합니다.
  • tag를 생략하면 먼저 tag 없는 객체를 조회합니다.
  • tag 없는 객체가 없으면 같은 filename의 버전 중 가장 최근 업데이트 객체를 조회합니다.

파일 메타 정보 조회

import requests

BASE_URL = "https://core.hyperx.dev"
PROJECT_CODE = "your-project-code"

resp = requests.get(
    f"{BASE_URL}/v1/storage/lookup",
    params={
        "key": "images/logo.png",
        # "tag": "v2",  # 특정 버전 조회 시 사용
    },
    headers={"x-project-code": PROJECT_CODE},
    timeout=10,
)
resp.raise_for_status()

meta = resp.json()
print("hash:", meta["hash"])
print("type:", meta["type"])
print("size:", meta["size"])
print("updatedAt(ms):", meta["updatedAt"])

파일 해시 조회

/v1/storage/hash는 8바이트 little-endian 바이너리를 반환합니다.
import requests

BASE_URL = "https://core.hyperx.dev"
PROJECT_CODE = "your-project-code"

resp = requests.get(
    f"{BASE_URL}/v1/storage/hash",
    params={"key": "images/logo.png"},
    headers={"x-project-code": PROJECT_CODE},
    timeout=10,
)
resp.raise_for_status()

hash_bytes = resp.content  # 정확히 8 bytes
hash_value = int.from_bytes(hash_bytes, byteorder="little", signed=False)
hash_hex = format(hash_value, "x")

print("hash bytes length:", len(hash_bytes))
print("hash (hex):", hash_hex)

파일 다운로드

먼저 /v1/storage/download-url로 임시 URL을 발급받은 뒤, 해당 URL로 실제 파일을 다운로드합니다.
import requests

BASE_URL = "https://core.hyperx.dev"
PROJECT_CODE = "your-project-code"

# 1) pre-signed download URL 발급
url_resp = requests.get(
    f"{BASE_URL}/v1/storage/download-url",
    params={
        "filename": "images/logo.png",
        # "tag": "v2",
    },
    headers={"x-project-code": PROJECT_CODE},
    timeout=10,
)
url_resp.raise_for_status()

download_url = url_resp.json()["url"]
print("download_url:", download_url)

# 2) 실제 파일 다운로드
file_resp = requests.get(download_url, timeout=30)
file_resp.raise_for_status()

with open("logo.png", "wb") as f:
    f.write(file_resp.content)

print("saved:", "logo.png", "bytes=", len(file_resp.content))

오류 응답

오류 시에는 아래 형태의 JSON이 반환됩니다.
{
  "error": "storage object not found"
}