Client class from the object-storage library and provides code examples for its methods.
Client
TheClient class manages interactions with Replit App Storage. This class features methods for performing operations on files in a bucket.
To import the class from the library, add the following line to your JavaScript code:
Client instance that interacts with Replit Object Storage:
Constructors
constructor- new Client(
options?):Client
| Name | Type | Description |
|---|---|---|
options? | ClientOptions | Configuration options for setting up the client. |
Client
Methods
copy
- copy(
objectName,destObjectName):Promise<Result<null,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to copy. |
destObjectName | string | The full path to copy the object to. |
Promise<Result<null, RequestError>>
delete
- delete(
objectName,options?):Promise<Result<null,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to delete. |
options? | DeleteOptions | Configurations for the delete operation. |
Promise<Result<null, RequestError>>
downloadAsBytes
- downloadAsBytes(
objectName,options?):Promise<Result<Buffer,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to download. |
options? | DownloadOptions | Configurations for the download operation. |
Promise<Result<Buffer, RequestError>>
downloadAsStream
- downloadAsStream(
objectName,options?):Readable
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to download. |
options? | DownloadOptions | Configurations for the download operation. |
Readable
downloadAsText
- downloadAsText(
objectName,options?):Promise<Result<string,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to download. |
options? | DownloadOptions | Configurations for the download operation. |
Promise<Result<string, RequestError>>
downloadToFilename
- downloadToFilename(
objectName,destFilename,options?):Promise<Result<null,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to download. |
destFilename | string | The path on the local filesystem to write the downloaded object to. |
options? | DownloadOptions | Configurations for the download operation. |
Promise<Result<null, RequestError>>
exists
- exists(
objectName):Promise<Result<boolean,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full path of the object to check. |
Promise<Result<boolean, RequestError>>
getBucket
- getBucket():
Promise<Bucket>
Promise<Bucket>
init
- init(
bucketId?):Promise<Bucket>
| Name | Type |
|---|---|
bucketId? | string |
Promise<Bucket>
list
- list(
options?):Promise<Result<StorageObject[],RequestError>>
| Name | Type | Description |
|---|---|---|
options? | ListOptions | Configurations for the list operation. |
Promise<Result<StorageObject[], RequestError>>
mapUploadOptions
- mapUploadOptions(
options?):undefined|UploadOptions
| Name | Type |
|---|---|
options? | UploadOptions |
undefined | UploadOptions
uploadFromBytes
- uploadFromBytes(
objectName,contents,options?):Promise<Result<null,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full destination path of the object. |
contents | Buffer | The raw contents of the object in byte form. |
options? | UploadOptions | Configurations for the upload operation. |
Promise<Result<null, RequestError>>
uploadFromFilename
- uploadFromFilename(
objectName,srcFilename,options?):Promise<Result<null,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full destination path of the object. |
srcFilename | string | The path of the file on the local filesystem to upload. |
options? | UploadOptions | Configurations for the upload operation. |
Promise<Result<null, RequestError>>
uploadFromStream
- uploadFromStream(
objectName,stream,options?):Promise<void>
| Name | Type | Description |
|---|---|---|
objectName | string | The full destination path of the object. |
stream | Readable | A readable stream from which to read the object’s contents. |
options? | UploadOptions | Configurations for the upload operation. |
Promise<void>
uploadFromText
- uploadFromText(
objectName,contents,options?):Promise<Result<null,RequestError>>
| Name | Type | Description |
|---|---|---|
objectName | string | The full destination path of the object. |
contents | string | The contents of the object in text form. |
options? | UploadOptions | Configurations for the upload operation. |
Promise<Result<null, RequestError>>