Skip to content

Instantly share code, notes, and snippets.

@sanath-kumar
Created August 23, 2018 12:57
Show Gist options
  • Save sanath-kumar/4b9967b4e2898daecc5bb23b896daabb to your computer and use it in GitHub Desktop.
Save sanath-kumar/4b9967b4e2898daecc5bb23b896daabb to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk')
var multer = require('multer')
var multerS3 = require('multer-s3')
AWS.config.loadFromPath('./s3_config.json')
var s3 = new AWS.S3()
var upload = multer({
storage: multerS3({
s3: s3,
bucket: 'YOUR-BUCKET-NAME',
acl: 'public-read',
metadata: function (req, file, cb) {
cb(null, {fieldName: file.fieldname});
},
key: function (req, file, cb) {
cb(null, Date.now().toString()+"-"+file.originalname)
}
})
});
module.exports = upload;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment