Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit d6490c2d authored by 65160258's avatar 65160258
Browse files

del Multer

parent b6310369
No related branches found
No related tags found
No related merge requests found
...@@ -145,29 +145,30 @@ router.get('/:id', async (req, res) => { ...@@ -145,29 +145,30 @@ router.get('/:id', async (req, res) => {
}); });
// ตั้งค่า Storage สำหรับ Multer // ตั้งค่า Storage สำหรับ Multer
const storage = multer.diskStorage({ // const storage = multer.diskStorage({
destination: (req, file, cb) => { // destination: (req, file, cb) => {
cb(null, 'public/uploads/'); // เก็บไฟล์ไว้ที่โฟลเดอร์ public/uploads/ // cb(null, 'public/uploads/'); // เก็บไฟล์ไว้ที่โฟลเดอร์ public/uploads/
}, // },
filename: (req, file, cb) => { // filename: (req, file, cb) => {
cb(null, Date.now() + path.extname(file.originalname)); // ตั้งชื่อไฟล์ให้ไม่ซ้ำกัน // cb(null, Date.now() + path.extname(file.originalname)); // ตั้งชื่อไฟล์ให้ไม่ซ้ำกัน
} // }
}); // });
// กำหนดเงื่อนไขการอัปโหลดไฟล์ // // กำหนดเงื่อนไขการอัปโหลดไฟล์
const upload = multer({ // const upload = multer({
storage: storage, // storage: storage,
limits: { fileSize: 5 * 1024 * 1024 }, // จำกัดขนาด 5MB // limits: { fileSize: 5 * 1024 * 1024 }, // จำกัดขนาด 5MB
fileFilter: (req, file, cb) => { // fileFilter: (req, file, cb) => {
const fileTypes = /jpeg|jpg|png|gif/; // const fileTypes = /jpeg|jpg|png|gif/;
const extName = fileTypes.test(path.extname(file.originalname).toLowerCase()); // const extName = fileTypes.test(path.extname(file.originalname).toLowerCase());
const mimeType = fileTypes.test(file.mimetype); // const mimeType = fileTypes.test(file.mimetype);
// if (extName && mimeType) {
// return cb(null, true);
// } else {
// return cb(new Error('Only images are allowed!'));
// }
// }
// });
if (extName && mimeType) {
return cb(null, true);
} else {
return cb(new Error('Only images are allowed!'));
}
}
});
module.exports = router; module.exports = router;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment