You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ass/s3.js

22 lines
616 B

const aws = require('aws-sdk');
const multer = require('multer');
const multerS3 = require('multer-s3');
const { s3endpoint, s3bucket, s3accessKey, s3secretKey } = require('./config.json');
const s3 = new aws.S3({
endpoint: new aws.Endpoint(s3endpoint),
credentials: new aws.Credentials({ accessKeyId: s3accessKey, secretAccessKey: s3secretKey })
});
const upload = multer({
storage: multerS3({
s3: s3,
bucket: s3bucket,
acl: 'public-read',
key: (_req, file, cb) => cb(null, file.originalname),
contentType: (_req, file, cb) => cb(null, file.mimetype)
})
}).single('file');
module.exports = upload;