I am new to Next js, what are the possible ways to upload files in mongodb using nextjs. Is it possible to upload directly in mongodb,if not what are the best hosting websites to upload my files. Thanks in advance
I have tried some code works well in react and I want solution for Nextjs framework
2
Answers
You can not directly upload images in mongodb, you need an URL of uploaded image, so you need an image host platform.
You can use https://cloudinary.com/
or either you can store base64 of image, but i guess this is not a good and optimal solution
You can store the URL of the image or base64 of the image in the MongoDB.
If you don’t want to store image in
base64 format
then you can keep the image URL inMongoDB database
and upload the image onAWS/Cloudinary
or any other platform as per your preference.Here is also the sample code for the implementation of this on Cludinary. In your .env file you need to place the given environment variables with their respective values.