Skip to content

Commit

Permalink
docs: enhance S3 presigned urls
Browse files Browse the repository at this point in the history
  • Loading branch information
alii committed Jan 22, 2025
1 parent 1e75cd5 commit c62bf0b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion docs/api/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,24 @@ When your production service needs to let users upload files to your server, it'

To facilitate this, you can presign URLs for S3 files. This generates a URL with a signature that allows a user to securely upload that specific file to S3, without exposing your credentials or granting them unnecessary access to your bucket.

The default behaviour is to generate a `GET` URL that expires in 24 hours. Bun attempts to infer the content type from the file extension. If inference is not possible, it will default to `application/octet-stream`.

```ts
import { s3 } from "bun";

// Generate a presigned URL that expires in 24 hours (default)
const url = s3.file("my-file.txt").presign({
const download = s3.presign("my-file.txt"); // GET, text/plain, expires in 24 hours

const upload = s3.presign("my-file", {
expiresIn: 3600, // 1 hour
method: 'PUT',
type: 'application/json', // No extension for inferring, so we can specify the content type to be JSON
});

// You can call .presign() if on a file reference, but avoid doing so
// unless you already have a reference (to avoid memory usage).
const myFile = s3.file("my-file.txt");
const presignedFile = myFile.presign({
expiresIn: 3600, // 1 hour
});
```
Expand Down

0 comments on commit c62bf0b

Please sign in to comment.