Artem Hostintsev
Artem Hostintsev

Reputation: 3

http://localhost:8080/uploads/1616174243802.png 404 (Not Found)

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

Answers (1)

Shubham Dixit
Shubham Dixit

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

Related Questions