From 2d59a98725116f97f56644f1b204d286561a6a63 Mon Sep 17 00:00:00 2001 From: Hasan Mustafa Date: Fri, 3 Jan 2025 09:30:18 -0600 Subject: [PATCH] feat(s3): add support for custom S3 endpoint and path-style addressing - Introduced `S3_ENDPOINT` and `S3_FORCE_PATH_STYLE` environment variables in the configuration file to enable compatibility with S3-compatible services. - Updated S3 client initialization in `storage.ts` to use custom endpoint and path-style addressing when required. --- src/core/config.ts | 2 ++ src/core/utils/storage.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/config.ts b/src/core/config.ts index dacae058..2e0daed5 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -53,6 +53,8 @@ export const config = { region: process.env.AWS_REGION, // binary files download host address. downloadUrl: process.env.AWS_DOWNLOAD_URL || process.env.DOWNLOAD_URL, + endpoint: process.env.S3_ENDPOINT, // optional - needed when working with S3-compatible services + forcePathStyle: toBool(process.env.S3_FORCE_PATH_STYLE), // optional - some S3 compatible services require path-style addressing }, // Config for Aliyun OSS (https://www.aliyun.com/product/oss) when storageType value is "oss". oss: { diff --git a/src/core/utils/storage.ts b/src/core/utils/storage.ts index 9f2c1af6..10639655 100644 --- a/src/core/utils/storage.ts +++ b/src/core/utils/storage.ts @@ -84,7 +84,10 @@ function uploadFileToS3(key: string, filePath: string, logger: Logger): Promise< sessionToken: _.get(config, 's3.sessionToken'), region: _.get(config, 's3.region'), }); - const s3 = new AWS.S3(); + const s3 = new AWS.S3({ + endpoint: _.get(config, 's3.endpoint'), + s3ForcePathStyle: _.get(config, 's3.forcePathStyle'), + }); fs.readFile(filePath, (err, data) => { if (err) { reject(new AppError(err));