while uploading file and creating a path , I am getting creating a folder error :-
Error: EACCES: permission denied, mkdir '/opt/bitnami/apps/NodeJS-Login/uploads'
at Object.fs.mkdirSync (fs.js:885:18)
at Function.sync (/opt/bitnami/apps/NodeJS-Login/node_modules/mkdirp/index.js:71:13)
at new DiskStorage (/opt/bitnami/apps/NodeJS-Login/node_modules/multer/storage/disk.js:21:12)
at module.exports (/opt/bitnami/apps/NodeJS-Login/node_modules/multer/storage/disk.js:65:10)
at new Multer (/opt/bitnami/apps/NodeJS-Login/node_modules/multer/index.js:15:20)
I am using bitnami on AWS to host my MEAN app.
on my main server.js file I have added this:-
app.use(multer({ dest: './uploads/',
rename: function (fieldname, filename) {
return filename;
},
}));
on schema model :-
companyLogo: {
data: Buffer,
type: String
}
and in controller for route :-
admin.companyLogo = fs.readFileSync(req.files.comLogo.path)
admin.companyLogo.type = 'image/png';
What should I do to make image upload ? Also do I have to pass other key values in form-data instead of raw ?