anacronw/multer-s3

req.file is undefined

Closed this issue · 0 comments

in sellers.js

const { s3 } = require('../s3')
var uploadBrandLogo = multer({
  storage: multerS3({
    s3,
    bucket: process.env.AWS_BUCKET_NAME,
    contentType: multerS3.AUTO_CONTENT_TYPE,
    metadata: (req, file, cb) => {
      cb(null, Object.assign({}, req.file.fieldname));
    },
    key: (req, file, cb) => {
      console.log(req.file)
      cb(null, file.fieldname + "_" + file.originalname + "_" + uuid())
    }
  })
}).single('brandLogo')

router.post("/", [uploadBrandLogo], (req, res, next) => {

  console.log(req.file)
}

in s3.js

AWS.config.update({
  accessKeyId: process.env.AWS_ACCESS_KEY,
  secretAccessKey: process.env.AWS_SECRET_KEY,
  region: process.env.AWS_BUCKET_REGION
})

const s3 = new AWS.S3({ apiVersion: '2006-03-01'})

module.exports.s3 = s3

I'm not sure what is going wrong here. Trying to upload a picture to an s3 bucket and would like to save key attribute in my database but it's stating that req.file is undefined when using postman to send the request. In postman, content-type is set to multipart/form-data, brandLogo is the name of the field used so, I'm really not sure what the issue is. There is no error message but just a console log reply of undefined and nothing sent to my s3 bucket.

any help is appreciated, thank you!