created API For Aplication Absensi
This commit is contained in:
24
app/middlewares/upload.js
Normal file
24
app/middlewares/upload.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const multer = require("multer");
|
||||
|
||||
// ✅ Pakai memoryStorage → file masuk ke RAM, ada file.buffer
|
||||
const storage = multer.memoryStorage();
|
||||
|
||||
// ✅ Filter hanya image (jpg, jpeg, png, webp)
|
||||
const fileFilter = (req, file, cb) => {
|
||||
const allowedTypes = ["image/jpeg", "image/jpg", "image/png", "image/webp"];
|
||||
if (allowedTypes.includes(file.mimetype)) {
|
||||
cb(null, true); // lolos
|
||||
} else {
|
||||
cb(new Error("Hanya file gambar yang diperbolehkan (jpg, jpeg, png, webp)"), false);
|
||||
}
|
||||
};
|
||||
|
||||
const upload = multer({
|
||||
storage,
|
||||
fileFilter,
|
||||
limits: {
|
||||
fileSize: 100 * 1024 * 1024,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = upload;
|
||||
Reference in New Issue
Block a user