Closed shadikkhan closed 7 years ago
Look at the documented key
parameter that can be passed a function to generate the s3 key
@badunk I am soryy, but did not get it as per my situation,
var upload = multer({ storage: multerS3({ s3: s3, bucket: 'some-bucket', metadata: function (req, file, cb) { cb(null, {fieldName: file.fieldname}); }, key: function (req, file, cb) { cb(null, Date.now().toString()) } }) })
in above code I have to set bucket : dynamicname
How can I do it? can you please help me little bit on this, i am new to this
Oops sorry misread your question
bucket
also accepts a function: https://github.com/badunk/multer-s3/blob/master/index.js#L81
@badunk Thanks a ton, Resolved
@AndroidHitchhiking I know it's late, but do you have an example of how you made the bucket accept a function? I've done the following but the upload doesn't work if I define bucket in this way:
bucket: (req, file, cb) => {
let bucketName = null
if (req.files[0].fieldname === 'type1') {
bucketName = 'some-bucket'
} else if (req.files[0].fieldname === 'type2') {
bucketName = 'some-other-bucket'
}
return bucketName
},
@javed24 instead of return bucketName
you'll want to do cb(null, bucketName)
This is done in order to support asynchronously specifying a bucket name...
@LinusU that works like a charm, awesome!
As per the given example there is no way to provide bucket name dynamically. Scenario is something like user would send data from request with bucket name and that name can be passed in bucket name.