Reputation: 3
I have a problem with an uploading photo to my website, here is a code which I have, but I have an issue that photo isn't displayed
import express from 'express';
import multer from 'multer';
import { isAuth, isAdmin } from '../utils';
const storage = multer.diskStorage({
destination(req, file, cb) {
cb(null, 'uploads/');
},
filename(req, file, cb) {
cb(null, `${Date.now()}.png`);
},
});
const upload = multer({ storage });
const uploadRouter = express.Router();
uploadRouter.post('/', isAuth, isAdmin, upload.single('image'), (req, res) => {
res.status(201).send({ image: `/${req.file.path}` });
});
export default uploadRouter;
Upvotes: 0
Views: 732
Reputation: 1
app.use(express.static(__dirname + '/uploads'));
Add this to serve static files from your app ,in your main file (index or main)
Upvotes: 2