Files
LAB5/21/controller/uploadController.js
MishaBagger 0956275ec4 MACHIN
2023-11-08 13:41:29 +03:00

30 lines
828 B
JavaScript

const multer = require("multer");
const storage = multer.diskStorage({
destination: function (req, file, cb) {
return cb(null, "./uploads");
},
filename: function (req, file, cb) {
return cb(null, `${Date.now()}-${file.originalname}`);
},
});
const upload = multer({ storage: storage });
const uploadImage = (req, res, next) => {
if (!req.file)
return res.status(400).send(`No file Uploaded <br>
<button onclick="window.location.href='/images'">Show Images</button>
<button onclick="window.location.href='/'">Back to Home</button>
`);
console.log(req.file);
res.send(
`Uploaded <br>
<button onclick="window.location.href='/images'">Show Images</button>
<button onclick="window.location.href='/'">Back to Home</button>
`
);
};
module.exports = { upload, uploadImage };