affanshahid / multer-storage-cloudinary

A Cloudinary multer storage engine
MIT License
104 stars 18 forks source link

Cannot read property 'uploader' of undefined. #9

Closed willnix86 closed 4 years ago

willnix86 commented 5 years ago

I get the above error at /Users/.../node_modules/multer-storage-cloudinary/lib/index.js:67:42

Below is the endpoint on my server. What could cause the issue? Isit an issue whereby middleware is messing something up?

router.use(urlParser); router.use(jsonParser); router.use('*', cloudinaryConfig)

router.post('/upload/:id', multerUploader, (req, res) => { console.log(req.file) // to see what is returned to you console.log(req.params); if (req.file) { const file = dataUri(req).content; const image = {}; image.url = req.file.url; image.id = req.file.public_id; return res.status(201).json(image); } });

jessetinell commented 5 years ago

Had the same error and solved it by removing .v2 from where I require Cloudinary.

Try replacing this: const cloudinary = require('cloudinary').v2; // Not working
With this ==> const cloudinary = require('cloudinary');

Muneeza93 commented 3 years ago

hi everyone i am a junior developer and i am working on a project to develop a medical app however my challenge is uploading an image to cloudinary firstly it returned undefined and i have tried to look for the problem but all has been in vain, any assistance is appreciated. Below is my group.controllers.js code trying to create a support group, using sequelize as my ORM;

const db = require("../models/index"); const cloudinary = require("../config/cloudinary"); const Groups = db.supportGroups;

// post a group exports.create = async (req, res) => { //console.log(req.body, req.file); try { const Group = await req.body.supportGroupName.toUpperCase(); const existGroup = await Groups.findOne({ where: { supportGroupName: Group }, }); await cloudinary.v2.uploader.upload( req.file.path, function (error, result) { if (error) { console.log(error); } console.log(result); } ); if (existGroup === null) { const newGroup = await Groups.create({ supportGroupName: Group, description: req.body.description, groupImageUrl: result.secure_url, imageId: result.public_id, }); return res.status(201).json(newGroup.supportGroupName); } else { res.status(409).json("Group already exists"); } } catch (err) { console.log(${err.message}); } };