I am trying to upload an image to amazon s3 using multer-s3
, but I am getting this error:
TypeError: Expected opts.s3 to be object node_modules/multer-s3/index.js:69:20
This is my server code:
var upload = multer({
storage: s3({
dirname: '/',
bucket: 'bucket',
secretAccessKey: 'key',
accessKeyId: 'key',
region: 'us-west-2',
filename: function (req, file, cb) {
cb(null, file.originalname);
}
})
});
app.post('/upload', upload.array('file'), function (req, res, next) {
res.send("Uploaded!");
});
Why I am getting this error?
s3
needs to be an object to be passed. According to the docs, the object needs to be like this:MulterS3 Docs
Complete and working Node Cheat | Upload to s3 using multer-s3 available.
Code:
For complete repo:
Clone node-cheat express_multer_s3, run
node app
followed bynpm install express body-parser aws-sdk multer multer-s3
.Happy Helping!
Zeeshan has answered very well still I want to add my 2 cents.
I believe in keeping one responsibility into one file, for better code organization and debugging purpose.
I have created a file for uploading
upload.js
.Which is imported inside my routes
routes.js