generated from nhcarrigan/template
This commit is contained in:
@@ -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}`);
|
||||
Reference in New Issue
Block a user