A 60-line Node.js script that uploads a folder of images to local S3 and generates a static HTML gallery from them.
- Creating a bucket and uploading objects with the AWS SDK v3
- Listing bucket contents and building presigned URLs
- That you don't need a "real" cloud to prototype a photo-sharing flow
- Node.js 20+
@aws-sdk/client-s3,@aws-sdk/s3-request-presigner- Floci S3
Make sure Floci is running:
docker run -d --name floci -p 4566:4566 \
-v /var/run/docker.sock:/var/run/docker.sock \
floci/floci:latestInstall deps and run:
npm install
node gallery.js ./photosOpen gallery.html in your browser. The images load directly from local S3 via presigned URLs.
The script does three things:
- Creates a bucket called
photo-gallery(no-op if it already exists). - Uploads every file in the directory you pass as an argument.
- Generates
gallery.htmlwith<img>tags pointing at presigned URLs that expire in an hour.
The interesting bit is the endpoint override:
const s3 = new S3Client({
endpoint: "http://localhost:4566",
region: "us-east-1",
credentials: { accessKeyId: "test", secretAccessKey: "test" },
forcePathStyle: true,
});That's the entire difference between this script and one that targets real AWS. Drop the endpoint line and it works against your real account.
- Swap
forcePathStyle: truefor virtual-hosted-style withlocalhost.floci.ioand see what changes. - Add a
--publicflag that sets the bucket ACL to public-read and drops the presigning. - Generate thumbnails with
sharpbefore upload, store originals and thumbs under different prefixes.
[your-handle-here] — replace this when you submit a real lab.