diff --git a/routes/posts.js b/routes/posts.js index 7869aa1d261be629b9102f83b8716871cf4d7cfc..57c71e85aefef1686bb30be463013636422679bc 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -145,29 +145,30 @@ router.get('/:id', async (req, res) => { }); // ตั้งค่า Storage สำหรับ Multer -const storage = multer.diskStorage({ - destination: (req, file, cb) => { - cb(null, 'public/uploads/'); // เก็บไฟล์ไว้ที่โฟลเดอร์ public/uploads/ - }, - filename: (req, file, cb) => { - cb(null, Date.now() + path.extname(file.originalname)); // ตั้งชื่อไฟล์ให้ไม่ซ้ำกัน - } - }); +// const storage = multer.diskStorage({ +// destination: (req, file, cb) => { +// cb(null, 'public/uploads/'); // เก็บไฟล์ไว้ที่โฟลเดอร์ public/uploads/ +// }, +// filename: (req, file, cb) => { +// cb(null, Date.now() + path.extname(file.originalname)); // ตั้งชื่อไฟล์ให้ไม่ซ้ำกัน +// } +// }); - // กำหนดเงื่อนไขการอัปโหลดไฟล์ - const upload = multer({ - storage: storage, - limits: { fileSize: 5 * 1024 * 1024 }, // จำกัดขนาด 5MB - fileFilter: (req, file, cb) => { - const fileTypes = /jpeg|jpg|png|gif/; - const extName = fileTypes.test(path.extname(file.originalname).toLowerCase()); - const mimeType = fileTypes.test(file.mimetype); +// // กำหนดเงื่อนไขการอัปโหลดไฟล์ +// const upload = multer({ +// storage: storage, +// limits: { fileSize: 5 * 1024 * 1024 }, // จำกัดขนาด 5MB +// fileFilter: (req, file, cb) => { +// const fileTypes = /jpeg|jpg|png|gif/; +// const extName = fileTypes.test(path.extname(file.originalname).toLowerCase()); +// 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;