Browse Source

more logs to understand File

master
Rich Brown 1 year ago
parent
commit
d6fcca6b97
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      routes/createRouter.js

+ 23
- 1
routes/createRouter.js View File

@@ -7,9 +7,31 @@ const upload = multer({ storage });

const createRouter = express.Router();

/* TODO: sanitize

function sanitizeFile(file, cb) {
// Define the allowed extension
let fileExts = ['png', 'jpg', 'jpeg', 'gif']
// Check allowed extensions
let isAllowedExt = fileExts.includes(file.originalname.split('.')[1].toLowerCase());
// Mime type must be an image
let isAllowedMimeType = file.mimetype.startsWith("image/")
if(isAllowedExt && isAllowedMimeType){
return cb(null ,true) // no errors
}
else{
// pass error msg to callback, which can be displaye in frontend
cb('Error: File type not allowed!')
}
}
*/

createRouter.post('/form', upload.single('file'), (req, res) => {
const { file, body: { title, body, arrayOfTags } } = req;
// console.log(file, body, title, arrayOfTags);

console.log(file, body, title, arrayOfTags);
console.log(typeof file);

return req.app.locals.mp
.create(
{


Loading…
Cancel
Save