Skip to content

Commit b4f3774

Browse files
Updated File Handling
1 parent cd266db commit b4f3774

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ const upload = multer({
122122
},
123123
fileFilter: (req, file, cb) => {
124124
// Check if file is an image
125+
const ext = path.extname(file.originalname).toLowerCase();
126+
const name = path.basename(file.originalname, path.extname(file.originalname));
125127
if (file.mimetype.startsWith('image/')) {
126-
cb(null, true);
128+
cb(null, `${name}${ext}`);
127129
} else {
128130
cb(new Error('Only image files are allowed!'), false);
129131
}

0 commit comments

Comments
 (0)