Problem loading Images in Public Folder
Unanswered
Levriero Sardo posted this in #help-forum
Levriero SardoOP
Here I create an API to upload images to the Public > UserData > Profile folder, when the image is successfully uploaded, then I open it in the browser, instead a 404 appears, but after I reload or restart the nextjs by turning it off and on again, the image can appear, maybe this is because nextjs does not support auto refresh in the public folder, here I run the nextjs project in Production and use Standalone mode, please provide a solution for this problem
7 Replies
@Levriero Sardo Here I create an API to upload images to the Public > UserData > Profile folder, when the image is successfully uploaded, then I open it in the browser, instead a 404 appears, but after I reload or restart the nextjs by turning it off and on again, the image can appear, maybe this is because nextjs does not support auto refresh in the public folder, here I run the nextjs project in Production and use Standalone mode, please provide a solution for this problem
Yes, nextjs only knows about static assets that were present at build time. You need to use a storage bucket, like Aws S3 or Cloudflare R2 to store those images
@Yi Lon Ma Yes, nextjs only knows about static assets that were present at build time. You need to use a storage bucket, like Aws S3 or Cloudflare R2 to store those images
Levriero SardoOP
but here the web is static
I don't use the cloud because I upload the uploaded images to the nextjs public folder, so that they can be viewed directly by people who use it without me having to give access to the cloud.
is there any solution for this?
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 Vercel Blob for persistent file storage.