Back to all posts
AWS1 min read

Upload Folder Images to S3 Bucket

Batch image uploads with predictable keys and safer progress reporting.

awss3uploads
Deployment and upload themed cover image

Upload Folder Images to S3 Bucket

Large uploads fail when the workflow is casual. Decide the target key pattern first, then upload deterministically.

Naming strategy

import { readdir } from "node:fs/promises";
import path from "node:path";

export async function collectUploadPlan(rootDirectory) {
  const fileNames = await readdir(rootDirectory);
  return fileNames.map((fileName) => ({
    localPath: path.join(rootDirectory, fileName),
    objectKey: `portfolio/gallery/${fileName}`,
  }));
}

Practical checks

  • confirm the bucket policy before the upload script starts
  • log failures per file, not only a global summary
  • preserve original file names unless there is a collision strategy

Result

You end up with a workflow that is easy to rerun, easy to diff, and easy to reason about from CI or an admin tool.