Upload images with Cloudinary, MongoDB and Express.

rm0909

Raphael Machado

Posted on July 13, 2022

Upload images with Cloudinary, MongoDB and Express.

We will have to create a middleware that uploads an image to cloudinary and returns it's image url

Create an account in cloudinary and choose programmable media.

Now go back to editor and create 3 variables in dotev file with these informations: CLOUD_NAME, API_KEY, API_SECRET.
You get that from cloudinary dashboard.

cloudinary connection

Create a folder 'utils' with a 'cloudinary.js' file.

cloudinary.js code

Create a 'controller' folder with a 'cloudinaryMiddleware.js' file.

middleware code
Now you just have to import and place it in your REST API like this:

rest api code

💖 💪 🙅 🚩
rm0909
Raphael Machado

Posted on July 13, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related