Browse Source

log file - debugging quotes around filename

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

+ 9
- 5
routes/createRouter.js View File

@@ -10,7 +10,9 @@ const storage = multer.diskStorage({
},
filename(req, file, cb) {
const { originalname } = file;
const fiver = Math.random().toString(36).substr(2, 5);
const fiver = Math.random()
.toString(36)
.substr(2, 5);
const ext = path.extname(originalname);
const rootName = originalname.replace(ext, '');
const newFilename = `${rootName}-${fiver}${ext}`;
@@ -25,17 +27,19 @@ const sanitizedFile = (file) => {
const fileExts = ['png', 'jpg', 'jpeg', 'gif'];
const isAllowedExt = fileExts.includes(file.originalname.split('.')[1].toLowerCase());
const isAllowedMimeType = file.mimetype.startsWith('image/');
return (isAllowedExt && isAllowedMimeType);
return isAllowedExt && isAllowedMimeType;
};

createRouter.post('/form', upload.single('file'), (req, res) => {
const { file, body: { title, body, arrayOfTags } } = req;
const {
file,
body: { title, body, arrayOfTags },
} = req;
console.log(file);
if (!sanitizedFile(file)) {
return res.status(403).json({ error: 'not an allowed filetype', url: null });
}
// formData smooshed array of Tags into a string. de-smoosh:
const tags = arrayOfTags.split(',');
console.log(tags);
return req.app.locals.mp
.create(
{


Loading…
Cancel
Save