Reputation: 1236
I am trying to upload file into AWS S3 using node js.
My requirement is to use dynamic value for bucket in multerS3 storage object
storage: multerS3({
s3: s3,
bucket: function (req, file, cb) {
console.log(" bucketName is >> "+JSON.stringify(req.bucketName));
cb(null, req.bucketName)
},
limits : {
fileSize : Number(Constants.UPLOADED_IMAGE_SIZE)
},
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
cb(null, file.originalname)
}
})
I am trying to pass value through request object and use it in bucket paramater. but it is coming as undefined.
in both cases req.bucketName and req.body.bucketName is coming as undefined.
Need help to resolve this problem.
My postman request is as below
Thanks for any help.
Upvotes: 7
Views: 2461
Reputation: 161
If you use Postman and have a file as a parameter, nothing else after it gets included.
Swap the order of your parameters, and have bucketName in front of the file and you will see it in the body.
The first picture shows an incorrect order, and body will not have a bucketName element. The second picture will pass through Busboy properly and the body will have a bucketName element of 'testName'.
Upvotes: 6