feat: add upload to s3 bucket script
Node.js CI / Lint and Test (push) Has been cancelled

This commit is contained in:
2025-12-01 14:02:19 -08:00
parent 0ec276c943
commit 18f3d15791
4 changed files with 1271 additions and 5 deletions
+50
View File
@@ -0,0 +1,50 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { readFile } from "node:fs/promises";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
import { input } from "@inquirer/prompts";
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
if (accessKeyId === undefined || secretAccessKey === undefined) {
throw new Error("AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY is not set");
}
const fileName = await input({
message: "Enter the ABSOLUTE PATH of the file to upload",
});
if (fileName === "") {
throw new Error("File name is not set");
}
const file = await readFile(fileName);
const uploadPath = await input({
message: "Enter the PATH to upload the file to",
});
if (uploadPath === "") {
throw new Error("Upload path is not set");
}
const s3 = new S3Client({
credentials: { accessKeyId, secretAccessKey },
endpoint: "https://hel1.your-objectstorage.com",
region: "hel1",
});
const command = new PutObjectCommand({
// eslint-disable-next-line @typescript-eslint/naming-convention -- AWS SDK
Body: file,
// eslint-disable-next-line @typescript-eslint/naming-convention -- AWS SDK
Bucket: "nhcarrigan",
// eslint-disable-next-line @typescript-eslint/naming-convention -- AWS SDK
Key: uploadPath,
});
await s3.send(command);
console.log(`Uploaded ${fileName} to ${uploadPath}`);