Methods
read
Read a file from the bucket.
async read(key: string): Promise<Buffer>
Parameters
The key/path of the file to read
Returns
The file contents as a Buffer
Example:
const content = await client.image.read("path/to/file.txt");
console.log(content.toString('utf-8'));
write
Write a file to the bucket.
async write(key: string, data: Buffer): Promise<void>
Parameters
The key/path where the file should be stored
The file contents as a Buffer
Example:
await client.image.write("path/to/file.txt", Buffer.from("Hello, World!"));
delete
Delete a file from the bucket.
async delete(key: string): Promise<void>
Parameters
The key/path of the file to delete
Example:
await client.image.delete("path/to/file.txt");
list
List files in the bucket with a given prefix.
async list(prefix: string): Promise<string[]>
Parameters
Filter results to keys starting with this prefix
Returns
Array of file keys matching the prefix
Example:
// List all files with empty prefix
const allFiles = await client.image.list("");
// List files in a specific directory
const docs = await client.image.list("documents/");
exists
Check if a file exists in the bucket.
async exists(key: string): Promise<boolean>
Parameters
The key/path of the file to check
Returns
True if the file exists, false otherwise
Example:
if (await client.image.exists("file.txt")) {
const config = await client.image.read("file.txt");
}
Presigned URLs
Generate presigned URLs for secure file access without exposing credentials.
async getDownloadUrl(key: string, options?: Partial<PresignUrlOptions>): Promise<string>
async getUploadUrl(key: string, options?: Partial<PresignUrlOptions>): Promise<string>
Parameters
options
Partial<PresignUrlOptions>
default:"{mode: Mode.Read, expiry: 300}"
Configuration with mode and expiry in seconds
Returns
The presigned URL for the file
Example:
// Download URL (default 5 minute expiry)
const downloadUrl = await client.image.getDownloadUrl("file.txt");
// Upload URL with custom expiry (1 hour)
const uploadUrl = await client.image.getUploadUrl("file.txt", {
mode: Mode.Write,
expiry: 3600
});