Multer was uploading files okay, but then suddenly the same code does not get the file object in the request. It's like multer is being ignored completely. When checking for file in the request, req.file is undefined.
function multerStore() {
return multer.diskStorage({
destination: function (req, file, cb) {
console.log(req);
execHomeDir().then(resp => {
const nameo = resp.replace("\n", "");
const folderPath = nameo + attachmentTemp;
createFolder(folderPath).then(resp=>{
cb(null, folderPath);
}).catch(ree=>{
cb(null, folderPath);
});
}).catch(ree => {
console.error('Error Multer');
console.error(ree);
const nameo = ree.replace("\n", "");
const folderPath = nameo + attachmentTemp;
createFolder(folderPath).then(resp=>{
cb(null, folderPath);
}).catch(ree=>{
cb(null, folderPath);
});
});
},
filename: function (req, file, cb) {
console.log(req);
console.log('Incoming file'+file.filename);
const name = setFileName('mexuser') + file.originalname;
cb(null, name);
}
});}
function multerOps() {
return multer({ storage: multerStore(), limits: fileLimiter });}const attachOps = multerOps('attachment', attachmentTemp);fileRouter.post('/:type', attachOps.single('attachment'),files.upload);