# S3 Reference ## Presigned URLs (GET / PUT) ```js import { S3Client, GetObjectCommand, PutObjectCommand } from "@aws-sdk/client-s3"; import { getSignedUrl } from "@aws-sdk/s3-request-presigner"; const client = new S3Client({ region: "us-east-1" }); // GET — default expiry 900s const getUrl = await getSignedUrl(client, new GetObjectCommand({ Bucket: "b", Key: "k" }), { expiresIn: 3600 }); // PUT const putUrl = await getSignedUrl(client, new PutObjectCommand({ Bucket: "b", Key: "k" }), { expiresIn: 3600 }); ``` Signing non-x-amz headers (e.g. Content-Type): ```js const url = await getSignedUrl(client, new PutObjectCommand({ Bucket: "b", Key: "k", ContentType: "image/png" }), { signableHeaders: new Set(["content-type"]), expiresIn: 3600, }); ``` Signing x-amz-* headers (must use `unhoistableHeaders`): ```js const url = await getSignedUrl(client, new PutObjectCommand({ Bucket: "b", Key: "k", ChecksumSHA256: sha }), { unhoistableHeaders: new Set(["x-amz-checksum-sha256"]), expiresIn: 3600, }); ``` ## Presigned POST (browser file upload) ```js import { createPresignedPost } from "@aws-sdk/s3-presigned-post"; const { url, fields } = await createPresignedPost(client, { Bucket: "b", Key: "uploads/${filename}", // ${filename} replaced by browser Expires: 600, Conditions: [["content-length-range", 0, 10485760]], Fields: { acl: "bucket-owner-full-control" }, }); // Use url + fields in an HTML
or FormData POST ``` ## Multipart Upload (lib-storage) Use `@aws-sdk/lib-storage` for large files, streams, or unknown-size bodies: ```js import { Upload } from "@aws-sdk/lib-storage"; import { S3Client } from "@aws-sdk/client-s3"; const upload = new Upload({ client: new S3Client({}), params: { Bucket: "b", Key: "k", Body: readableStream }, queueSize: 4, // parallel part uploads (default 4) partSize: 5 * 1024 * 1024, // min 5MB per part leavePartsOnError: false, }); upload.on("httpUploadProgress", (progress) => console.log(progress)); await upload.done(); ``` ## Waiters ```js import { S3Client } from "@aws-sdk/client-s3"; import { waitUntilBucketExists, waitUntilObjectExists } from "@aws-sdk/client-s3"; const client = new S3Client({}); await waitUntilBucketExists({ client, maxWaitTime: 60 }, { Bucket: "my-bucket" }); await waitUntilObjectExists({ client, maxWaitTime: 120 }, { Bucket: "my-bucket", Key: "my-key" }); ``` Available S3 waiters: `waitUntilBucketExists`, `waitUntilBucketNotExists`, `waitUntilObjectExists`, `waitUntilObjectNotExists`. Waiter config: `maxWaitTime` (seconds, required), `minDelay` (default 5s), `maxDelay` (default 120s). Other services export their own `waitUntil*` functions from the same client package.