Next.js Discord

Discord Forum

Storing user uploads within the public folder

Unanswered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Are there any issues I should anticipate when storing user uploads (primarily profile pictures) in the public folder?

The site would be used purely for demonstration purposes and not production so there won't be lots of traffic. I'm mainly concerned about deployment, would there be permissions preventing the project from running with providers, such as Vercel?

I like the idea of being able to spin up the project at any time without having to worry about free tier limits etc.

5 Replies

the public folder is mostly for static assets, so this means it is not a good idea to store user uploaded content there. the reason being that the files are read at build time so if you upload something there while the app is running it won't be available to the users. a better approach is to use services dedicated to this task like S3
yeah, try using the prod build with next start. the dev server has some different behaviors from the prod one
@Rafael Almeida yeah, try using the prod build with `next start`. the dev server has some different behaviors from the prod one
West African LionOP
Yep, you're right. So pretty much my options are either use a 3rd party service like S3 or host a separate server, like express js etc? I guess having a separate server would be good for getting websockets working but it kind of makes the NextJS api folder feel a bit pointless as I could achieve everything in there directly via express. Is there a benefit to keeping everything except file uploads / websockets in the nextjs api folder or would there be no difference compared to me just moving it all over to express?
the differences would be the Next.js features that you would not have in the express server. but imo I would just move everything over if you have a dedicated API. it's better to have everything in the same place and is easier to organize the API