Upload Folder Images to S3 Bucket
Batch image uploads with predictable keys and safer progress reporting.
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.