runlot
데이터스토리지

env.storage

put, get, head, delete, list, presign API를 제공합니다.

export interface Storage {
  put(key: string, body: BodyInit | null, opts?: { contentType?: string }): Promise<StorageObject>;
  /** 키가 없으면 `null`을 반환합니다. 404 오류가 아닙니다. */
  get(key: string): Promise<(StorageObject & { body: ReadableStream<Uint8Array> | null }) | null>;
  head(key: string): Promise<StorageObject | null>;
  /** 여러 번 호출해도 안전합니다. 없는 키를 삭제해도 성공합니다. */
  delete(key: string): Promise<void>;
  list(opts?: { prefix?: string; cursor?: string; limit?: number }): Promise<StorageListPage>;
  /** 서명 URL입니다. GET과 PUT만 지원합니다. ttl은 초 단위(기본 300, 최대 3600)입니다. */
  presign(key: string, opts?: { method?: "GET" | "PUT"; ttl?: number }): Promise<string>;
}

객체 메타데이터의 형식은 다음과 같습니다.

export interface StorageObject {
  key: string;
  size: number;
  etag: string;
  contentType: string;
  /** RFC 1123 형식이며 비어 있을 수 있습니다. */
  lastModified: string;
}

존재하지 않는 키는 null을 반환합니다

gethead는 키가 없으면 null을 반환합니다. 존재 여부 확인은 흔한 작업이므로, 매번 try/catch로 404 오류를 처리하지 않도록 설계했습니다.

delete는 여러 번 호출해도 안전합니다. 존재하지 않는 키를 삭제해도 성공합니다.

키 규칙

키는 /로 구분한 경로 형태로 작성합니다.

await env.storage.put("users/42/avatar.png", body);

빈 경로 구간과 . 또는 ..는 사용할 수 없습니다.

await env.storage.put("a//b", body);   // TypeError
await env.storage.put("a/../b", body); // TypeError

URL 파서는 /o/../x/x로 정규화한 뒤에는 원래 경로를 검사할 수 없습니다. 그래서 워커가 요청을 보내기 전에 이러한 키를 차단합니다.

키 전체 길이는 최대 1024바이트입니다.

프로젝트 간 파일 격리

저장 키에는 프로젝트 식별자가 자동으로 추가됩니다. 다른 프로젝트의 객체를 키로 지정할 수 없습니다.

이 페이지의 목차