Documentation Index
Fetch the complete documentation index at: https://docs.replit.com/llms.txt
Use this file to discover all available pages before exploring further.
이 참조 가이드는 object-storage 라이브러리의 Client 클래스를 설명하고, 메서드에 대한 코드 예제를 제공합니다.
Client
Client 클래스는 Replit App Storage와의 상호작용을 관리합니다. 이 클래스는 bucket 내 파일에 대한 작업을 수행하는 메서드를 제공합니다.
라이브러리에서 클래스를 가져오려면 JavaScript 코드에 다음 줄을 추가하세요:
import { Client } from "@replit/object-storage";
다음 코드를 사용하여 Replit Object Storage와 상호작용하는 Client 인스턴스를 생성하세요:
const client = new Client();
생성자
constructor
- new Client(
options?): Client
Replit App Storage와 상호작용하는 새 Client 인스턴스를 생성합니다.
Parameters
| Name | Type | Description |
|---|
options? | ClientOptions | 클라이언트 설정을 위한 구성 옵션입니다. |
Returns
Client
메서드
copy
- copy(
objectName, destObjectName): Promise<Result<null, RequestError>>
동일한 bucket 내에서 object를 복사합니다.
이 메서드는 대상 경로에 이미 존재하는 object를 덮어씁니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 복사할 object의 전체 경로입니다. |
destObjectName | string | object를 복사할 전체 경로입니다. |
Returns
Promise<Result<null, RequestError>>
delete
- delete(
objectName, options?): Promise<Result<null, RequestError>>
bucket에서 object를 삭제합니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 삭제할 object의 전체 경로입니다. |
options? | DeleteOptions | 삭제 작업에 대한 구성입니다. |
Returns
Promise<Result<null, RequestError>>
downloadAsBytes
- downloadAsBytes(
objectName, options?): Promise<Result<Buffer, RequestError>>
object를 다운로드하고 원시 내용을 buffer로 반환합니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 다운로드할 object의 전체 경로입니다. |
options? | DownloadOptions | 다운로드 작업에 대한 구성입니다. |
Returns
Promise<Result<Buffer, RequestError>>
downloadAsStream
- downloadAsStream(
objectName, options?): Readable
object 내용의 읽기 가능한 stream을 생성합니다.
stream은 다운로드 중 발생하는 오류를 전달합니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 다운로드할 object의 전체 경로입니다. |
options? | DownloadOptions | 다운로드 작업에 대한 구성입니다. |
Returns
Readable
downloadAsText
- downloadAsText(
objectName, options?): Promise<Result<string, RequestError>>
object를 다운로드하고 내용을 문자열로 반환합니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 다운로드할 object의 전체 경로입니다. |
options? | DownloadOptions | 다운로드 작업에 대한 구성입니다. |
Returns
Promise<Result<string, RequestError>>
downloadToFilename
- downloadToFilename(
objectName, destFilename, options?): Promise<Result<null, RequestError>>
object를 다운로드하여 로컬 파일 시스템의 지정된 위치에 저장합니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 다운로드할 object의 전체 경로입니다. |
destFilename | string | 다운로드한 object를 쓸 로컬 파일 시스템의 경로입니다. |
options? | DownloadOptions | 다운로드 작업에 대한 구성입니다. |
Returns
Promise<Result<null, RequestError>>
exists
- exists(
objectName): Promise<Result<boolean, RequestError>>
bucket에 object가 존재하는지 확인합니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | 확인할 object의 전체 경로입니다. |
Returns
Promise<Result<boolean, RequestError>>
getBucket
- getBucket():
Promise<Bucket>
Returns
Promise<Bucket>
init
- init(
bucketId?): Promise<Bucket>
Parameters
Returns
Promise<Bucket>
list
- list(
options?): Promise<Result<StorageObject[], RequestError>>
bucket 내 모든 object의 목록을 반환합니다.
Parameters
| Name | Type | Description |
|---|
options? | ListOptions | 목록 작업에 대한 구성입니다. |
Returns
Promise<Result<StorageObject[], RequestError>>
mapUploadOptions
- mapUploadOptions(
options?): undefined | UploadOptions
Parameters
| Name | Type |
|---|
options? | UploadOptions |
Returns
undefined | UploadOptions
uploadFromBytes
- uploadFromBytes(
objectName, contents, options?): Promise<Result<null, RequestError>>
메모리 내 바이트 표현을 사용하여 object를 업로드합니다.
이 메서드는 동일한 이름의 기존 object를 덮어씁니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | object의 전체 대상 경로입니다. |
contents | Buffer | 바이트 형식의 object 원시 내용입니다. |
options? | UploadOptions | 업로드 작업에 대한 구성입니다. |
Returns
Promise<Result<null, RequestError>>
uploadFromFilename
- uploadFromFilename(
objectName, srcFilename, options?): Promise<Result<null, RequestError>>
로컬 파일 시스템에서 bucket으로 파일을 업로드합니다.
이 메서드는 동일한 이름의 기존 object를 덮어씁니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | object의 전체 대상 경로입니다. |
srcFilename | string | 업로드할 로컬 파일 시스템의 파일 경로입니다. |
options? | UploadOptions | 업로드 작업에 대한 구성입니다. |
Returns
Promise<Result<null, RequestError>>
uploadFromStream
- uploadFromStream(
objectName, stream, options?): Promise<void>
제공된 stream에서 내용을 읽어 object를 업로드합니다.
stream은 업로드 중 발생하는 오류를 전달합니다. 이 메서드는 동일한 이름의 기존 object를 덮어씁니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | object의 전체 대상 경로입니다. |
stream | Readable | object 내용을 읽을 읽기 가능한 stream입니다. |
options? | UploadOptions | 업로드 작업에 대한 구성입니다. |
Returns
Promise<void>
uploadFromText
- uploadFromText(
objectName, contents, options?): Promise<Result<null, RequestError>>
메모리 내 텍스트 표현을 사용하여 object를 업로드합니다.
이 메서드는 동일한 이름의 기존 object를 덮어씁니다.
Parameters
| Name | Type | Description |
|---|
objectName | string | object의 전체 대상 경로입니다. |
contents | string | 텍스트 형식의 object 내용입니다. |
options? | UploadOptions | 업로드 작업에 대한 구성입니다. |
Returns
Promise<Result<null, RequestError>>
메서드 예제
다음 섹션에서는 Replit Object Storage SDK를 사용하여 파일을 관리하는 코드 예제를 제공합니다.
텍스트로 object 가져오기
const { ok, value: textValue, error } = await client.downloadAsText('file.json');
if (!ok) {
// ... handle error ...
}
object를 원시 바이트 표현으로 가져오기
const { ok, value: bytesValue, error } = await client.downloadAsBytes('file.png');
if (!ok) {
// ... handle error ...
}
stream으로 object 가져오기
const { ok, value: stream, error } = await client.downloadAsStream('file.json');
if (!ok) {
// ... handle error ...
}
파일 시스템으로 object 다운로드
const { ok, error } = await client.downloadToFilename('file.json', destFilename);
if (!ok) {
// ... handle error ...
}
bucket 내 object 나열
const { ok, value, error } = await client.list();
if (!ok) {
// ... handle error ...
}
텍스트로 object 업로드
const { ok, error } = await client.uploadFromText('file.json', data);
if (!ok) {
// ... handle error ...
}
bytes로 object 업로드
const { ok, error } = await client.uploadFromBytes('file.png', data);
if (!ok) {
// ... handle error ...
}
파일 시스템에서 object 업로드
const { ok, error } = await client.uploadFromFilename('file.json', srcFilename);
if (!ok) {
// ... handle error ...
}
stream으로 object 업로드
const { ok, error } = await client.uploadFromStream('file.json', stream);
if (!ok) {
// ... handle error ...
}
bucket에서 object 삭제
const { ok, error } = await client.delete('file.json');
if (!ok) {
// ... handle error ...
}