constructor

bun.S3Client.constructor

constructor S3Client(
options?: S3Options

Create a new instance of an S3 bucket so that credentials can be managed from a single instance instead of being passed to every method.

@param options

The default options to use for the S3 client. Can be overridden by passing options to the methods.

@returns

A new S3Client instance

const bucket = new Bun.S3Client({
  accessKeyId: "your-access-key",
  secretAccessKey: "your-secret-key",
  bucket: "my-bucket",
  endpoint: "https://s3.us-east-1.amazonaws.com",
  sessionToken: "your-session-token",
});

// Get a reference to a file in the bucket:
const file = bucket.file("my-file.txt");

// Write to it and read it back:
await file.write("Hello Bun!");
await file.text();

// To delete the file:
await bucket.delete("my-file.txt");

// To write a file without returning the instance:
await bucket.write("my-file.txt", "Hello Bun!");