Next.js Discord

Discord Forum

Image uploads to /public folder work but images don't get served in production

Unanswered
Giant resin bee posted this in #help-forum
Open in Discord
Avatar
Giant resin beeOP
i upload files to "public/uploads" directory in next.js using fs, uploading and serving images work perfectly in development, my client deployed the application on a dedicated vps or machine, the image upload works but the images do not get served, i get invalid requested resource when i try to serve them, whats the workaround for this? i dont want to use any 3rd party service like s3 or cloudinary

9 Replies

Avatar
Image
read the 2nd point
you have to use a service like s3
or redeploy your nextjs app on each file upload
Avatar
@Giant resin bee Only way is to use third services
I don't think you will re-deploy your project everytime you have a new asset put into your public folder
Avatar
Giant resin beeOP
well I did a workaround

- made an API route that reads the public directory at run time using fs and sends the image in response

while serving the image
- redirected all image requests to the directory in the the public folder which I specified to the API route I made, used a middleware for this
Avatar
Serrano Bulldog
I also facing the same issue , while working on profile picture uploads it's working on dev but in prod it's only working for existing uploaded images while uploading new image, it's uploading on public/images but not get served 😕


Hw i can use S3 ,R2 and other third party to make this work..?
Avatar