Damian Buttle
Damian Buttle

Reputation: 75

Multer s3 Filename

I'm using multer s3 to upload images from my node.js app to my amazon bucket. I'm using the date together with the original filename to create the new filename; however, when I try to display the new filename it just displays as undefined. This is my code:

    var upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: 'imagebucket',
    acl: 'public-read',
    metadata: function (req, file, cb) {
      cb(null, Object.assign({}, req.body));
    },
    key: function (req, file, cb) {
        console.log(file);
        cb(null, Date.now()+file.originalname);
    }
  })
})

app.post('/upload', upload.single('upload'), function(req, res, next) {
  res.send('Successfully uploaded ' + req.file.length + ' files!')
})

Any help would be welcomed.

Upvotes: 2

Views: 3755

Answers (2)

user6016061
user6016061

Reputation: 105

Try req.file.location in the last function middle ware

Upvotes: 0

AnC
AnC

Reputation: 651

It looks like you are not passing a string to the key function

Please try this:

key: function (req, file, cb) {
    console.log(file);
    cb(null, `${Date.now().toString()}${file.originalname}`);
}

Upvotes: 1

Related Questions