I am using nodejs multer to upload an image file to image uploads directory. After uploading, how can this particular image be displayed in html img tag in client browser. What is the url?
When I type in http://localhost:3000/uploads/1591342432.jpeg, it says cannot get the file.
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "./uploads/");
},
filename: function (req, file, cb) {
cb(null, Date.now() + ".jpeg");
},
});
const upload = multer({ storage: storage });
router.post("/upload", upload.single("file"), async (req, res) => {
try {
console.log("uploading...");
console.log(req.file.filename);
res.json({ cool: "yes" });
// res.json({ file: req.file });
} catch (error) {
console.log(error);
}
});