0

I am following this youtube video - https://www.youtube.com/watch?v=Rw_QeJLnCK4 , which step by step guides on how to upload an image to cloudinary.

this is the cloudinary config -

enter image description here

router.post('/create',auth,createBlog)

this is the route at which i am handling image upload

And here in the createBlog controller , i am importing that cloudinary config and doing the same as mentioned in the youtube video -

enter image description here

I am able to get the bas64encoded string of the image in the 'req.body.image' which i sent from frontend.

But the console.log(response) gives me this error -

TypeError: Cannot read property 'upload' of undefined

I have also created a preset named 'my_blogwebsite' in cloudinary associated with the folder of the same name.

I am using ES6 module for importing and exporting instead of commonJS in my express app.And in the video the instructor requires the cloudinary in commonJS like this -

const cloudinary = require("cloudinary").v2;

But i dont know how to add that '.v2' in ES6 module.I tried searching on google about this but had no luck.I think achieving this will solve my issue but i am not sure.

Edit - This is my folder structure

enter image description here

Please help me resolve this , thank you

10
  • Does it work if you replace cloudinary.uploader.upload with cloudinary.v2.uploader.upload? Commented Sep 25, 2021 at 8:47
  • I tried adding what you mentioned and this is the error i got - TypeError: Cannot read property 'uploader' of undefined Commented Sep 25, 2021 at 8:54
  • What is the path on your system where the Cloudinary module is installed? By default, you should be able to import it from ./node_modules/cloudinary/cloudinary.js Commented Sep 25, 2021 at 9:04
  • @Aleksandar the path is the same as you wrote. Commented Sep 25, 2021 at 9:08
  • In that case, did you update the import path in your config (first screenshot)? Commented Sep 25, 2021 at 9:24

3 Answers 3

1

you can import it this way:


import {v2 as cloudinary} from "cloudinary"

Sign up to request clarification or add additional context in comments.

Comments

0

You can try this way:

import cloudinaryModule from "cloudibary";

const cloudinaryModule = cloudinaryModule.v2;

Comments

0

cloudinary config file

import dotenv from "dotenv"
dotenv.config()
import { v2 } from "cloudinary"

v2.config({
  cloud_name: process.env.CLOUDINARY_NAME,
  api_key: process.env.CLOUDINARY_KEY,
  api_secret: process.env.CLOUDINARY_SECRET,
})

export default v2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.