I have decided to go the S3 route for storing images instead of doing it with Gridfs. But I am still confused as to how MongoDB will integrate with Multer and S3.
For instance, lets say I have a collection of documents for each user. It's assumed that the documents themselves won't contain the profile pics that will get uploaded to my S3 cloud.
But when I display a list of users in the front-end, how can I make sure that the correct profile pic is displayed for each user?
I am looking over the multer-s3 documentation, and I notice that metadata sets the name of the file that is to be uplaoded to S3 (I think?).
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())
}
})
})
I am thinking maybe a good solution to this problem would be name each file that is uploaded as the same name as the user who will use it. Can I tinker with the metadata and key functions so that they are the same name as the username of whoever uploads them? What exactly does cb
do and what does each of it paramters represent?