'Invalid signature string to sign Node/Cloudinary

I’m having a problem with image uploads with the Cloudinary API.

I have the app running on Heroku. I’m using Node for my backend. The app runs fine, until a user tries to post an image. I then get the following error message:

Invalid Signature ******************************. String to sign - 'timestamp=.

I used the same setup in another app, and it works fine. I’ve followed some stack overflow threads on the problem, but I’m not getting a useful answer that I understand.

I’ve set up the environment variables in Heroku the same way I did on another app, and it works. I’ve also installed the Cloudinary and Multer packages in my package.json file.

Any ideas what I’m doing wrong here?

Below is my code:


var multer   = require('multer');

var storage = multer.diskStorage({

  filename: function(req, file, callback) {

    callback(null, Date.now() + file.originalname);

  }

});

var imageFilter = function (req, file, cb) {

    // accept image files only

    if (!file.originalname.match(/\.(jpg|jpeg|png|gif)$/i)) {

        return cb(new Error('Only image files are allowed!'), false);

    }

    cb(null, true);

};

var upload = multer({ storage: storage, fileFilter: imageFilter});

 

var cloudinary = require('cloudinary');

cloudinary.config({

  cloud_name: 'digi9mjbp',

  api_key: process.env.CLOUDINARY_API_KEY,

  api_secret: process.env.CLOUDINARY_API_SECRET

})


       router.post("/", middleware.isLoggedIn, upload.single('image'), 
        function(req, res) {
         cloudinary.v2.uploader.upload(req.file.path, function(err,result){
           if(err){
            req.flash("error", err.message);
            return res.redirect("back");
        }
       // add cloudinary url for the image to the topic object under image 
       property
       req.body.topic.image = result.secure_url;
       //add image's public_id to topic object
       req.body.topic.imageId = result.public_id;
       // add author to topic
       req.body.topic.author = {
        id: req.user._id,
        username: req.user.username
       };
       Topic.create(req.body.topic, function(err, topic){
        if (err) {
          req.flash('error', err.message);
          return res.redirect('back');
        }
        res.redirect('/topics/' + topic.id);
       });
       });
       });



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source