anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 190 forks source link

It is possible make some kind of function for each uploaded file when posting multiple files at once? #82

Closed code-by closed 3 years ago

code-by commented 7 years ago

I have following for upload files into S3

const upload = extension => multer({
  storage: multerS3({
    s3,
    bucket,
    acl,
    metadata(req, file, cb) {
      cb(null, { fieldName: file.fieldname });
    },
    ...
  }),
});

router.post(
  '/upload',
  upload('jpg').array('files', 5),
  (req, res) => {
    console.log(req.files);
    ...

It is possible to make some kind of function for each single uploading file (to write some information about file into DB before multer begin uploading next file from array('files', 5) ) (for example, if writing data into DB failed multer need to abort uploading rest of files) or for this I need upload each file separately?

cpheimbach commented 6 years ago

I am having the same use case. Did you find a solution? Currently I do this via the req object in the route which handles the file.

Ovi commented 4 years ago

+1

LinusU commented 3 years ago

You could use the metadata function that you have in your example.

Happy to consider a specific function if someone makes a clear API proposal.

Closing since this is quite old...