Update README
This commit is contained in:
40
server.js
40
server.js
@@ -238,15 +238,43 @@ const upload = multer({
|
||||
fileSize: 10 * 1024 * 1024 // 10MB limit
|
||||
},
|
||||
fileFilter: (req, file, cb) => {
|
||||
// Allow text files, PDFs, and images
|
||||
const allowedTypes = /jpeg|jpg|png|gif|pdf|txt|doc|docx/;
|
||||
const extname = allowedTypes.test(path.extname(file.originalname).toLowerCase());
|
||||
const mimetype = allowedTypes.test(file.mimetype);
|
||||
// Define allowed file types for RAG processing - only text-extractable documents
|
||||
const allowedExtensions = ['.pdf', '.txt', '.doc', '.docx', '.xlsx', '.xls', '.md', '.json', '.csv', '.xml'];
|
||||
const allowedMimeTypes = [
|
||||
'application/pdf',
|
||||
'text/plain',
|
||||
'text/markdown',
|
||||
'text/csv',
|
||||
'text/xml',
|
||||
'application/xml',
|
||||
'application/json',
|
||||
'application/msword',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
];
|
||||
|
||||
if (mimetype && extname) {
|
||||
const fileExtension = path.extname(file.originalname).toLowerCase();
|
||||
const fileMimeType = file.mimetype.toLowerCase();
|
||||
|
||||
// Check if file extension is allowed
|
||||
const isExtensionAllowed = allowedExtensions.includes(fileExtension);
|
||||
|
||||
// Check if MIME type is allowed
|
||||
const isMimeTypeAllowed = allowedMimeTypes.includes(fileMimeType);
|
||||
|
||||
// Additional validation for specific file types
|
||||
if (isExtensionAllowed && isMimeTypeAllowed) {
|
||||
return cb(null, true);
|
||||
} else {
|
||||
cb(new Error('Only text files, PDFs, and images are allowed!'));
|
||||
// Provide specific error messages for different rejection reasons
|
||||
if (!isExtensionAllowed) {
|
||||
return cb(new Error(`File type "${fileExtension}" is not supported. Only document files (PDF, Word, Excel, text files) are allowed for RAG processing.`));
|
||||
} else if (!isMimeTypeAllowed) {
|
||||
return cb(new Error(`MIME type "${fileMimeType}" is not supported. Please upload valid document files only.`));
|
||||
} else {
|
||||
return cb(new Error('Invalid file type. Only text-extractable documents are allowed to prevent RAG corruption.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user