File Upload & Storage
Multer Configuration
Local Storage (temporary):
// config/multer.js
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, req.tempFolder); // Dynamic temp folder
},
filename: (req, file, cb) => {
cb(null, `${Date.now()}-${file.originalname}`);
}
});
Minio Object Storage
Configuration (config/minio.js):
const minioClient = new Minio.Client({
endPoint: process.env.MINIO_ENDPOINT,
port: parseInt(process.env.MINIO_PORT),
useSSL: process.env.MINIO_USE_SSL === 'true',
accessKey: process.env.MINIO_ACCESS_KEY,
secretKey: process.env.MINIO_SECRET_KEY
});
Upload Flow:
- File uploaded to temp directory via Multer
- Image processed/compressed with Sharp
- File uploaded to Minio
- Temp file deleted
- Minio URL stored in database
Image Processing
const sharp = require('sharp');
// Compress and resize
await sharp(inputPath)
.resize(800, 800, { fit: 'inside' })
.jpeg({ quality: 80 })
.toFile(outputPath);
No Comments