DEV Community

Tony Lobbin
Tony Lobbin

Posted on

How to view images after they uploaded in public/uploads folder with Next.js?

Hi, Every One. I have some problem while upload and view images in next.js app.
I upload images to %project%/public/uploads folder
after upload, I can't load uploaded image in next.js app.
when I run the app with dev it works well.
but I run the app with prod it doesn't works.

Image description

Image description

Top comments (1)

Collapse
 
elitesuper profile image
Tony Lobbin

This was because of server.
I found the answer.

`app.prepare().then(() => {
const server = express();
// server.use(fileUpload())

server.use("/upload", express.static(__dirname + "/public/uploads"));
server.all("*", (req, res) => {
return handle(req, res);
});
server.listen(port, (err) => {
if (err) throw err;`

and use /upload/image_path