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.
Navigate to All Settings > Raw Data Export > CSV Upload. Toggle the switch to ON. Select Amazon S3 Bucket from the dropdown menu. Enter your Access Key ID, Secret Access Key, and bucket name.
It's not possible to append to an existing file on AWS S3. You can delete existing file and upload new file with same name.
There are three ways in which you can upload a file to amazon S3.
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With