Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/filesharing is added #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

KaustubhBankar
Copy link

//In public / frontend changes -> added button for attachment;

const handleFileChange = (event) => {
setFile(event.target.files[0]); // Save the selected file to state
};

// In backend ---->

const multer = require("multer");
const path = require("path"); // Add this line to import the path module
const fs = require("fs");

const uploadDir = path.join(__dirname, "uploads");

// Check if the uploads directory exists, if not, create it
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
console.log(Created uploads directory at ${uploadDir});
}

// Multer configuration
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, "uploads/"); // Where files will be stored
},
filename: (req, file, cb) => {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
cb(null, file.fieldname + '-' + uniqueSuffix + path.extname(file.originalname)); // Rename the file with a unique suffix
}
});

const upload = multer({ storage: storage });

module.exports = upload;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant