diff --git a/backend/src/routes/documents.ts b/backend/src/routes/documents.ts index f3db9a71..ea3c77fa 100644 --- a/backend/src/routes/documents.ts +++ b/backend/src/routes/documents.ts @@ -32,11 +32,31 @@ const upload = multer({ fileSize: parseInt(process.env['MAX_FILE_SIZE'] || '262144000'), // 250MB default }, fileFilter: (req, file, cb) => { - // Only allow PDF files - if (file.mimetype === 'application/pdf') { + // Allow PDF files with multiple possible MIME types + const allowedMimeTypes = [ + 'application/pdf', + 'application/x-pdf', + 'application/acrobat', + 'applications/vnd.pdf', + 'text/pdf', + 'text/x-pdf' + ]; + + // Check MIME type or file extension + const isValidPDF = allowedMimeTypes.includes(file.mimetype) || + file.originalname.toLowerCase().endsWith('.pdf'); + + // Log for debugging + console.log('Upload attempt:', { + mimetype: file.mimetype, + filename: file.originalname, + isValid: isValidPDF + }); + + if (isValidPDF) { cb(null, true); } else { - cb(new Error('Only PDF files are allowed')); + cb(new Error(`Only PDF files are allowed. Received: ${file.mimetype} for file: ${file.originalname}`)); } }, });