Upload an image with Cloudinary (#16)

Why Cloudinary?

For starters, it’s free.

How can you get started?

To start using Cloudinary’s services, you first need to sign up and verify your account. You can do this on their website.

npm install cloudinary
yarn add cloudinary

Step 1: Configure Cloudinary

The first step after installing the cloudinary node package, is to configure your account in your code-base. To do this, you’d need to get your cloud name, API key & API secret from Cloudinary.

What your cloudinary dashboard should look like
cloudinary.config({    
cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET
});

Step 2: Upload an Image

The second step is leveraging the Cloudinary API to actually upload an image.

cloudinary.v2.uploader.upload("/uploads/image-name.jpg", 
(err, result) => {
if(err){
throw err;
}else{
console.log("Successfully uploaded image to cloudinary!");
}
});
  1. Why do I need to chain .v2 in between the cloudinary API and it’s uploader method?

Conclusion

And that’s how you upload an image with Cloudinary! Isn’t it easy? I would recommend taking a look at Cloudinary’s Node JS SDK Documentation if you have the chance. It’s really simple and easy-to-read.

Thanks for reading through! 🚀 I hope this was helpful :)

Visit my website to learn more about me and get in touch. Or reach out to me on social media: twitter | github

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store