Fileupload Gunner Project -

if (mimetype && extname) return cb(null, true); else cb(new Error('Only images, PDFs, and ZIPs are allowed'));

);

// File filter const fileFilter = (req, file, cb) => zip/; const extname = allowedTypes.test(path.extname(file.originalname).toLowerCase()); const mimetype = allowedTypes.test(file.mimetype); fileupload gunner project

const upload = multer( storage: storage, limits: fileSize: 10 * 1024 * 1024 , // 10MB fileFilter: fileFilter ); if (mimetype && extname) return cb(null, true); else

try const response = await fetch('/api/upload', method: 'POST', body: formData ); const result = await response.json(); alert('Upload success: ' + result.file.storedName); catch (err) console.error(err); alert('Upload failed'); if (mimetype && extname) return cb(null

// Upload route app.post('/api/upload', upload.single('file'), (req, res) => if (!req.file) return res.status(400).json( error: 'No file uploaded' );