Skip to content

Commit 7f949bf

Browse files
committed
Update s3.md
1 parent 24a2c9b commit 7f949bf

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

Diff for: docs/api/s3.md

+64-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const url = metadata.presign({
2525
await metadata.delete();
2626
```
2727

28-
S3 is the [de facto standard](https://en.wikipedia.org/wiki/De_facto_standard) internet filesystem. You can use Bun's S3 API with S3-compatible storage services like:
28+
S3 is the [de facto standard](https://en.wikipedia.org/wiki/De_facto_standard) internet filesystem. Bun's S3 API works with S3-compatible storage services like:
2929

3030
- AWS S3
3131
- Cloudflare R2
@@ -42,7 +42,7 @@ There are several ways to interact with Bun's S3 API.
4242

4343
`Bun.s3` is equivalent to `new Bun.S3Client()`, relying on environment variables for credentials.
4444

45-
To explicitly set credentials, you can pass them to the `Bun.S3Client` constructor.
45+
To explicitly set credentials, pass them to the `Bun.S3Client` constructor.
4646

4747
```ts
4848
import { S3Client } from "bun";
@@ -76,7 +76,7 @@ Like `Bun.file(path)`, the `S3Client`'s `file` method is synchronous. It does ze
7676

7777
### Reading files from S3
7878

79-
If you've used the `fetch` API, you're familiar with the `Response` and `Blob` APIs. `S3File` extends `Blob`, so you can use the same methods on it as you would for a `Response` or a `Blob`.
79+
If you've used the `fetch` API, you're familiar with the `Response` and `Blob` APIs. `S3File` extends `Blob`. The same methods that work on `Blob` also work on `S3File`.
8080

8181
```ts
8282
// Read an S3File as text
@@ -231,7 +231,7 @@ const url = s3file.presign({
231231

232232
### `new Response(S3File)`
233233

234-
To quickly redirect users to a presigned URL for an S3 file, you can pass an `S3File` instance to a `Response` object as the body.
234+
To quickly redirect users to a presigned URL for an S3 file, pass an `S3File` instance to a `Response` object as the body.
235235

236236
```ts
237237
const response = new Response(s3file);
@@ -258,6 +258,43 @@ Response (0 KB) {
258258

259259
Bun's S3 implementation works with any S3-compatible storage service. Just specify the appropriate endpoint:
260260

261+
### Using Bun's S3Client with AWS S3
262+
263+
AWS S3 is the default. You can also pass a `region` option instead of an `endpoint` option for AWS S3.
264+
265+
```ts
266+
import { S3Client } from "bun";
267+
268+
// AWS S3
269+
const s3 = new S3Client({
270+
accessKeyId: "access-key",
271+
secretAccessKey: "secret-key",
272+
bucket: "my-bucket",
273+
// endpoint: "https://s3.us-east-1.amazonaws.com",
274+
// region: "us-east-1",
275+
});
276+
```
277+
278+
### Using Bun's S3Client with Google Cloud Storage
279+
280+
To use Bun's S3 client with [Google Cloud Storage](https://cloud.google.com/storage), set `endpoint` to `"https://storage.googleapis.com"` in the `S3Client` constructor.
281+
282+
```ts
283+
import { S3Client } from "bun";
284+
285+
// Google Cloud Storage
286+
const gcs = new S3Client({
287+
accessKeyId: "access-key",
288+
secretAccessKey: "secret-key",
289+
bucket: "my-bucket",
290+
endpoint: "https://storage.googleapis.com",
291+
});
292+
```
293+
294+
### Using Bun's S3Client with Cloudflare R2
295+
296+
To use Bun's S3 client with [Cloudflare R2](https://developers.cloudflare.com/r2/), set `endpoint` to the R2 endpoint in the `S3Client` constructor. The R2 endpoint includes your account ID.
297+
261298
```ts
262299
import { S3Client } from "bun";
263300

@@ -268,20 +305,38 @@ const r2 = new S3Client({
268305
bucket: "my-bucket",
269306
endpoint: "https://<account-id>.r2.cloudflarestorage.com",
270307
});
308+
```
309+
310+
### Using Bun's S3Client with DigitalOcean Spaces
311+
312+
To use Bun's S3 client with [DigitalOcean Spaces](https://www.digitalocean.com/products/spaces/), set `endpoint` to the DigitalOcean Spaces endpoint in the `S3Client` constructor.
313+
314+
```ts
315+
import { S3Client } from "bun";
271316

272-
// DigitalOcean Spaces
273317
const spaces = new S3Client({
274318
accessKeyId: "access-key",
275319
secretAccessKey: "secret-key",
276320
bucket: "my-bucket",
321+
// region: "nyc3",
277322
endpoint: "https://<region>.digitaloceanspaces.com",
278323
});
324+
```
325+
326+
### Using Bun's S3Client with MinIO
327+
328+
To use Bun's S3 client with [MinIO](https://min.io/), set `endpoint` to the URL that MinIO is running on in the `S3Client` constructor.
329+
330+
```ts
331+
import { S3Client } from "bun";
279332

280-
// MinIO
281333
const minio = new S3Client({
282334
accessKeyId: "access-key",
283335
secretAccessKey: "secret-key",
284336
bucket: "my-bucket",
337+
338+
// Make sure to use the correct endpoint URL
339+
// It might not be localhost in production!
285340
endpoint: "http://localhost:9000",
286341
});
287342
```
@@ -346,7 +401,7 @@ await file.delete();
346401

347402
### `S3Client.prototype.write`
348403

349-
You can call `.write` on the `S3Client` instance to write a file to S3.
404+
To upload or write a file to S3, call `write` on the `S3Client` instance.
350405

351406
```ts
352407
const client = new Bun.S3Client({
@@ -364,7 +419,7 @@ await client.write("my-file.txt", new Response("Hello World!"));
364419

365420
### `S3Client.prototype.delete`
366421

367-
To delete a file from S3, you can use the `delete` method.
422+
To delete a file from S3, call `delete` on the `S3Client` instance.
368423

369424
```ts
370425
const client = new Bun.S3Client({
@@ -380,7 +435,7 @@ await client.delete("my-file.txt");
380435

381436
### `S3Client.prototype.exists`
382437

383-
To check if a file exists in S3, you can use the `exists` method.
438+
To check if a file exists in S3, call `exists` on the `S3Client` instance.
384439

385440
```ts
386441
const client = new Bun.S3Client({

0 commit comments

Comments
 (0)