anacronw / multer-s3

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

Target folder #33

Closed rideddy84 closed 8 years ago

rideddy84 commented 8 years ago
var upload = multer({
  storage: multerS3({
    s3: s3,
    bucket: 'web-test-2016',
    acl: 'public-read',
    key: function (req, file, cb) {
      cb(null, makeid() + '_' + file.originalname)
      //Date.now().toString()
    }
  })
})

In this case, how can I set the destination folder name? Thanks.

LinusU commented 8 years ago

S3 doesn't have real folders, to get what you want you can just prepend folder name followed by a / to the key.

edit: s/append/prepend

caseyhyde commented 7 years ago

Just tried this, and works great! However by append, he means prepend. Ie:

key: function (req, file, cb) {
     cb(null, 'foo-folder/' + makeid() + '_' + file.originalname)
}

puts file in folder named foo-folder with a url of https://s3.amazonaws.com/bucketname/foo-folder/id_file.originalname