adding s3 endpoint url

This commit is contained in:
Daniël 2024-06-09 13:22:57 +02:00
parent c0fb7f8569
commit be25ea36f2
3 changed files with 10 additions and 1 deletions

View file

@ -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

View file

@ -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 {

View file

@ -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 });