host images during runtime locally
Answered
Winter Wren posted this in #help-forum
Winter WrenOP
I have some code which stores images in /public folder. It works in dev mode, but in prod mode the images arent served. I guess this is by purpose. Is there any way to host the images throught nextjs and use its image optimization features?
Answered by Rafael Almeida
from the docs (https://nextjs.org/docs/app/building-your-application/optimizing/static-assets):
the public folder is not meant to serve uploaded files, you need to use a separate service for that
Only assets that are in the public directory at build time will be served by Next.js. Files added at request time won't be available. We recommend using a third-party service like AWS S3 for persistent file storage.
the public folder is not meant to serve uploaded files, you need to use a separate service for that
4 Replies
Winter WrenOP
I have built it using npm build inside of an docker image. I mount the public folder inside. When I restart the new images become available, but during runtime added images are 404
from the docs (https://nextjs.org/docs/app/building-your-application/optimizing/static-assets):
the public folder is not meant to serve uploaded files, you need to use a separate service for that
Only assets that are in the public directory at build time will be served by Next.js. Files added at request time won't be available. We recommend using a third-party service like AWS S3 for persistent file storage.
the public folder is not meant to serve uploaded files, you need to use a separate service for that
Answer
Winter WrenOP
yeah makes sense, thanks