title: How to upload an image to cloudinary
body: <p>I want to upload an image to cloudinary form my NodeJS api, i have my model, in this model i have a field called image, this field is type string and here I want to save the url that a receive as response of cloudinary.</p>
  
  <p>Here is my model.js</p>
  
  <pre><code>'use strict';
  
  const mongoose = require('mongoose');
  
  const CursoSchema = mongoose.Schema({
    name: {
      type: String,
      required: true
    },
    image: {
      type: String,
    },
    description: {
      type: String,
      required: true
    }
  });
  
  module.exports = mongoose.model('Curso', CursoSchema);
  </code></pre>
  
  <p>And my controller.js, here is where I have to save the url, I tried with the method of cloudinary docs.</p>
  
  <pre><code>var imageFile = req.files.image;
  cloudinary.uploader.upload(imageFile.path, function(result){
    if (result.url) { res.status(200).send({url: result.url});
    }else {
      console.log('Error uploading to cloudinary');
   }
  });
  </code></pre>
  
  <p>but I just uploaded images. Here is my controller.js</p>
  
  <pre><code>'use strict';
  
  const Curso = require('../models/curso');
  const config = require('../config');
  const cloudinary = require('cloudinary');
  
  cloudinary.config({
    cloud_name: 'something',
    api_key: 'somthingelse',
    api_secret: 'andotherthing'
  })
  
  function saveCurso(req, res) {
    let curso = new Curso();
    let params = req.body;
    curso.name =  params.name;
    curso.description = params.description;
    //How to get the image and upload it to cloudinary
  
    curso.save((err, cursoSaved)=&gt;{
      if(err){return res.status(500).send({message:'Error'});}
      if(!cursoSaved) return res.status(404).send({message: 'Empty'});
      return res.status(200).send({curso: cursoSaved});
    });
  }
  
  module.exports = {
    saveCurso,
  }
  </code></pre>
  
  <p>And my routes.js file:</p>
  
  <pre><code>'use strict';
  
  const express = require('express');
  const api = express.Router();
  const cursoController = require('../controllers/curso');
  
  api.post('/curso', cursoController.saveCurso);
  
  module.exports =  api;
  </code></pre>
  
  <p>I want to save the data with the name, description and in the image, i want to save the url from cloudinary.</p>
  
  <p>I saved some images in cloudinary but I can't find the way to save only the url in my image field </p>
  
  <p>NOTE: I'm using body-parser and this is my app.js </p>
  
  <pre><code>'use strict';
  
  const bodyParser = require('body-parser');
  const express = require('express');
  const app = express();
  
  const curso_routes = require('./routes/curso');
  
  app.use(bodyParser.urlencoded({extended:true}));
  app.use(bodyParser.json());
  
  app.use('/api', curso_routes);
  
  module.exports = app;
  </code></pre>