diff --git a/docs/api/s3.md b/docs/api/s3.md index d9082335216cdf..5dda1b2da126b9 100644 --- a/docs/api/s3.md +++ b/docs/api/s3.md @@ -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 }); ```