Previously I was sending my Javascript object via post to the node backend. which was working alright. The problem is I have to move to form data because I'm changing avatar in our json to s3 url instead of base64. so I installed multer and multer-s3. I am not able to either upload the avatar or to update other Javascript Object properties.
My Javascript object is of the same structure as
{
info: {
name: 'abc',
avatar: Blob Instance
},
address: {},
education: {}
}
My multier code is
const multer = require('multer');
const aws = require('aws-sdk');
const BUCKET_NAME = 'myBucket';
var multerS3 = require('multer-s3');
aws.config.accessKeyId = 'someId';
aws.config.secretAccessKey = 'someKey';
aws.config.region = 'us-east-2';
var upload = multer({
storage: multerS3({
s3: new aws.S3(),
bucket: BUCKET_NAME,
acl: 'public-read',
contentType: multerS3.AUTO_CONTENT_TYPE,
metadata: function(req, file, cb) {
console.log(file);
cb(null, { fieldName: file.fieldname });
},
key: function(req, file, cb) {
let id = req.user._id;
cb(null, id + '/' + Date.now().toString() + '_' + file.originalname);
},
}),
});
My route is
router.post(
'/',
authorizeUser,
upload.single('avatar'),
controller.updateWithAsscociations
);
In my controller func updateWithAsscociations I get nothing. Neither the logoURL nor the rest