Skip to main content

MERN app, Invalid signature upload error

Comments

3 comments

  • Aditi Madan
    Hi,
     
    Are you setting the Cloudinary API key and secret in the config or are you generating the signature on your own? Images can be uploaded using signed or unsigned upload and signed upload can be achieved either by specifying Cloudinary config in the back-end or you can generate your own signature on the backend.
     
    Here is a code snippet specifying the config and Cloudinary takes care of the signature generation:
     
    var cloudinary = require('cloudinary');

    cloudinary.config({

    cloud_name: '<your cloud name>',

    api_key: '<your api key>',

    api_secret: ''<your api secret>

    });



    app.post('/', upload.any([{ name: "file1" },{ name: "file2" }]), (req, res) => {

    var files=req.files;

    if(files){

    files.forEach(function(file){

    cloudinary.uploader.upload(file.path, function(result) {

    console.log(result);

    });

    });
     
    Regards,
    Aditi
    1
  • Decombat

    Thanks for your answer !

    Yes I use key and secret

    const { config } = require("cloudinary").v2
    const dotenv = require("dotenv")
    
    dotenv.config()
    const cloudinaryConfig = (req, res, next) => {
        config({
            cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
            api_key: process.env.CLOUDINARY_API_KEY,
            api_secret: process.env.CLOUDINARY_API_SECRET,
        })
        next()
    }
    
    module.exports = {
        cloudinaryConfig: cloudinaryConfig
    }
    app.use("/", cloudinaryConfig)

    Everything working fine locally. it's when I put the app on Heroku that I've got a signature error...

    I import the environment key in Heroku, so they shouldn't be any differences. 

    0
  • Decombat

    I just found the error.

    I re-checked my environment variables in Heroku.

    Turns out I've forgot an extra space at the end of my cloudinary key... 

    Everything working just fine now. Thanks for your help anyway ! 

    0

Post is closed for comments.