0

I use multer/multer-s3 to upload a Profilepicture to Amazon S3. The Upload works well when i use a static filename like 'userPhoto_' which matches the the fieldname in the form.

var upload = multer({
  storage: multerS3({
      s3: s3,
      bucket: '<bucketname>',
      key: function (req, file, cb) {
          cb(null, file.fieldname);
      }
  })
});

router.post('/api/photo', upload.single('userPhoto_123'), function (req,res) {
  res.end("Uploaded!");
});

In my .ejs File i have the Input Field like

<input class="ui input" type="file" name="userPhoto_<%=person.id%>" />

So the question is how to pass the FieldName including the person.id to the upload.single - Middleware.

Thanks!

1 Answers1

0

modify bucket value as -

req: is normal express request

bucket: (req, file, cb) => { cb(null, ${req.dynamic_name}); };

Rahul Singh
  • 341
  • 1
  • 6