Issue with Displaying Dynamically Added Images in Next.js After Build
Unanswered
Bee posted this in #help-forum
BeeOP
Hi! I’ve encountered an issue in my Next.js 14 project:
I’ve implemented a feature where users can upload images, and these are stored in the public folder. In development mode (npm run dev), everything works perfectly: images are added to the folder, and I can view them on the page or access them via a direct URL (e.g., /image/project/1733143942094.jpeg).
However, after building the project (npm run build) and running it in production mode (npm run start):
The images are physically present in the public folder.
The correct path to them is generated on the page, but they do not render.
Trying to access the images directly via a full URL (e.g., https://example.com/image/project/1733143942094.jpeg) results in a 404 error.
I understand that Next.js doesn’t account for dynamically added files in the public folder after the build process. What would you recommend in this case? Are there any approaches to make Next.js handle such files, or would it be better to rely on API routes or an additional server for dynamically serving resources?
I’d appreciate any advice or solutions! 😊
I’ve implemented a feature where users can upload images, and these are stored in the public folder. In development mode (npm run dev), everything works perfectly: images are added to the folder, and I can view them on the page or access them via a direct URL (e.g., /image/project/1733143942094.jpeg).
However, after building the project (npm run build) and running it in production mode (npm run start):
The images are physically present in the public folder.
The correct path to them is generated on the page, but they do not render.
Trying to access the images directly via a full URL (e.g., https://example.com/image/project/1733143942094.jpeg) results in a 404 error.
I understand that Next.js doesn’t account for dynamically added files in the public folder after the build process. What would you recommend in this case? Are there any approaches to make Next.js handle such files, or would it be better to rely on API routes or an additional server for dynamically serving resources?
I’d appreciate any advice or solutions! 😊
5 Replies
@Yi Lon Ma You need to implement something like aws s3, uploadthing or cloudflare r2 to store those images in a persistent storage
BeeOP
So it won’t be possible to implement this in Next.js itself?
BeeOP
😮💨