I am making a simple authentication page with mongoDB and next-auth, users can upload a photo to their profile, what database can I use to save and upload the image?
Hello,
best use the reference method, upload the image files to some cloud storage with a free tier, then save the URL in the data base.
There are ways to store files directly to a data base, but it’s not best practice, especially with images. They can for example bloat a data base, making back ups long and expensive.
What cloud storage can I use for the user to save their avatar photo?
Here’s a GitHub page about the topic comparing the free tiers.
I’m usually going with Azure since I’m using ASP.NET core for my APIs.
Be sure to choose a service that let’s you put everything on hold when any limits of the free offers are reached (storage room and/ or monthly requests).
You can also handle the files yourself.
https://www.google.com/search?q=next+13+js+multiple+file+upload
https://www.google.com/search?q=nextjs+13+multer
But using a CDN might be better anyway and it will depend on the deployment/host as well (file size limits, speed, etc.).
what you mean with myself?
I mean store the images “locally” (on the server) as part of the project and link to the files in the DB.
I still don’t get it, you can’t save files to the front-end server, right?
If you can run Node you can usually use the file system part of it. If you look at the search links I gave, you can see some examples.
But yes, it will depend on the environment and host what you are allowed to do with the local file system.
In any case, using a dedicated image host/CDN is likely better anyway.
I did it with Firebase, but what are the benefits of storing the images on the server and how difficult is that?
Mainly control. You are not locked into some vendor-specific solution.
But there are plenty of downsides as well. Like storage and bandwidth costs, a lack of proper global distribution of the assets (which is what a CDN gives you), security considerations that might be mitigated using a third-party service, etc.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.