35 lines
704 B
JavaScript
35 lines
704 B
JavaScript
![]() |
import multer from "multer";
|
||
|
import multerS3 from "multer-s3";
|
||
|
import AWS from "aws-sdk";
|
||
|
|
||
|
// Environment Variables
|
||
|
const {
|
||
|
MCL_S3_ENDPOINT: s3Endpoint,
|
||
|
MCL_S3_ACCESS_KEY_ID: s3KeyId,
|
||
|
MCL_S3_ACCESS_KEY: s3Key,
|
||
|
} = process.env;
|
||
|
|
||
|
export const mcl = "mcl";
|
||
|
|
||
|
export const s3 = new AWS.S3({
|
||
|
endpoint: s3Endpoint,
|
||
|
accessKeyId: s3KeyId,
|
||
|
secretAccessKey: s3Key,
|
||
|
sslEnabled: true,
|
||
|
s3ForcePathStyle: true,
|
||
|
});
|
||
|
|
||
|
const storage = multerS3({
|
||
|
s3,
|
||
|
bucket,
|
||
|
contentType: multerS3.AUTO_CONTENT_TYPE,
|
||
|
metadata: (req, file, cb) => {
|
||
|
cb(null, { fieldName: file.fieldname });
|
||
|
},
|
||
|
key: (req, file, cb) => {
|
||
|
cb(null, Date.now().toString());
|
||
|
},
|
||
|
});
|
||
|
|
||
|
export const upload = multer({ storage });
|