MERN app, Invalid signature upload error
Hello,
I've got this error
Invalid Signature ... String to sign - 'folder=/site×tamp=1585851883&use_filename=1'
http_code: 401
my upload request :
const { uploader, api } = require("cloudinary").v2
const { dataUri } = require("../multer.js")
async function upload(req, res) {
if (req.files.file[0]) {
const image = dataUri(req.files.file[0]).content
return uploader.upload(image, {
folder: '/site',
use_filename: true
})
.then((result) => {
var item = {
title: req.body.title,
content: req.body.content,
category: req.body.category,
public_id: result.public_id,
file: result.url,
file_transformation: result.eager[0].url
}
var data = new ImagesSchema(item)
data.save()
return res.status(200).json({ message: 'Your image has been uploded' })
})
.catch((err) => res.status(400).json({
message: 'someting went wrong while processing your request',
data: { err }
}))
}
}
any clue?
0
-
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.More information here: https://cloudinary.com/documentation/upload_images#upload_responseUnsigned upload: https://cloudinary.com/documentation/upload_images#unsigned_uploadHere 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,
Aditi1 -
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 -
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.
Comments
3 comments