From be25ea36f2eecc488706892b6edd97466667398a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl?= <15849319+abcdan@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:22:57 +0200 Subject: [PATCH] adding s3 endpoint url --- .env.example | 1 + controllers/file.controller.js | 1 + engines/s3.engine.js | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 0299d59..9eca3f5 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,7 @@ AWS_ACCESS_KEY_ID=your_aws_access_key_id AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key AWS_REGION=your_aws_region S3_BUCKET_NAME=your_s3_bucket_name +S3_ENDPOINT=your_s3_endpoint # If you are using local storage, this is the path where the files will be uploaded LOCAL_UPLOAD_PATH=uploads diff --git a/controllers/file.controller.js b/controllers/file.controller.js index 195d45d..51a0c9c 100644 --- a/controllers/file.controller.js +++ b/controllers/file.controller.js @@ -24,6 +24,7 @@ if (storageMode === "local") { secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, region: process.env.AWS_REGION, bucketName: process.env.S3_BUCKET_NAME, + endpoint: process.env.S3_ENDPOINT, }; storageEngine = initializeS3Storage(multerOptions, fileNameLength, s3Config); } else { diff --git a/engines/s3.engine.js b/engines/s3.engine.js index b0d945d..d1a90b2 100644 --- a/engines/s3.engine.js +++ b/engines/s3.engine.js @@ -4,7 +4,14 @@ const AWS = require("aws-sdk"); const { nanoid } = require("nanoid"); const initializeS3Storage = (multerOptions, fileNameLength, s3Config) => { - const s3 = new AWS.S3(s3Config); + const s3 = new AWS.S3({ + accessKeyId: s3Config.accessKeyId, + secretAccessKey: s3Config.secretAccessKey, + endpoint: s3Config.endpoint, + s3ForcePathStyle: true, + signatureVersion: "v4", + }); + const storage = multer.memoryStorage(); const upload = multer({ storage: storage, ...multerOptions });