humanizerx / server /upload.js
mmrwinston001's picture
Upload 5 files (#2)
83cc215 verified
// backend/upload.js
const path = require('path');
const multer = require('multer');
const fs = require('fs');
// Ensure uploads folder exists
const uploadsDir = path.join(__dirname, 'uploads');
if (!fs.existsSync(uploadsDir)) {
fs.mkdirSync(uploadsDir, { recursive: true });
}
const upload = multer({
dest: uploadsDir, // Absolute path to uploads folder
limits: { fileSize: 15 * 1024 * 1024 }, // 15MB max
fileFilter: (req, file, cb) => {
const allowedTypes = [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'text/plain'
];
if (allowedTypes.includes(file.mimetype)) {
cb(null, true);
} else {
cb(new Error('Invalid file type. Only PDF, Word, and TXT files are allowed.'));
}
}
});
module.exports = upload;