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

changed multer profile pic upload logic #60

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions client/src/js/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Development configuration
export const CONFIG = {
API_ENDPOINT: 'http://localhost:5000'
}
// export const CONFIG = {
// API_ENDPOINT: 'http://localhost:5000'
// }


// Production configuration
// export const CONFIG = {
// API_ENDPOINT: 'https://student-zynergy.vercel.app'
// }
export const CONFIG = {
API_ENDPOINT: 'https://student-zynergy.vercel.app'
}
16 changes: 14 additions & 2 deletions client/src/pages/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ <h1 class="input-box-heading">Login</h1>
</span>
<p>Email</p>
</div>
<input class="input-box" name="email" autocomplete="off" />
<input
class="input-box"
type="email"
name="email"
autocomplete="off"
required
/>
</div>
<div class="input-box-div">
<input class="input-box" name="password" autocomplete="off" />
<input
class="input-box"
type="password"
name="password"
autocomplete="off"
required
/>
<div class="input-box-text-div">
<span class="material-symbols-outlined login-form-icon">
lock
Expand Down
55 changes: 25 additions & 30 deletions server/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,45 +93,40 @@ const token = (req, res) => {
}

// profile pic upload

const multer = require('multer');
const path = require('path');

// Set storage engine
const storage = multer.diskStorage({
destination: './uploads/profile_pics',
filename: (req, file, cb) => {
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
}
const multerS3 = require('multer-s3');
const AWS = require('aws-sdk');

// Configure AWS S3
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_REGION,
});

// Init upload
// Set up Multer to use S3 for storage
const upload = multer({
storage: storage,
limits: { fileSize: 1000000 }, // Limit file size to 1MB
fileFilter: (req, file, cb) => {
checkFileType(file, cb);
}
}).single('profileImage');

// Check file type
function checkFileType(file, cb) {
const filetypes = /jpeg|jpg|png|gif/;
const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
const mimetype = filetypes.test(file.mimetype);

if (mimetype && extname) {
return cb(null, true);
} else {
cb('Error: Images Only!');
}
}
storage: multerS3({
s3: s3,
bucket: 'your-s3-bucket-name',
metadata: (req, file, cb) => {
cb(null, { fieldName: file.fieldname });
},
key: (req, file, cb) => {
cb(null, Date.now().toString() + '-' + file.originalname);
},
}),
});







module.exports = {
register,
login,
token
token,
upload
}
Loading
Loading