Grokking ExpressJS
Vote

0% completed

​

Validating File Types and Sizes

Rename a text file from notes.txt to photo.png, upload it, and a common Multer filter accepts it as an image. The configuration below allows JPEG, PNG and PDF attachments up to 2 MB, and the test sent it 33 bytes of plain text named photo.png:

const ALLOWED_TYPES = ["image/jpeg", "image/png", "application/pdf"]; const upload = multer({ dest: "uploads/", limits: { fileSize: 2 * 1024 * 1024, files: 1 }, fileFilter: (req, file, cb) => { if (ALLOWED_TYPES.includes(file.mimetype)) { cb(null, true); } else { cb(null, false); } }, });

``

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content