Error attempting signed upload
Hello I am getting a 401 when attempting to upload a signed image.
{"error":{"message":"Invalid Signature 75bb020b2b23e7c691efbe042d7465d6b5830293. String to sign - 'timestamp=1669696920&upload_preset=ml_default'."}}
FrontEnd:
api
.get(`/images`)
.then((res) => {
const {signature, timestamp} = res.data;
const url= `https://api.cloudinary.com/v1_1/${process.env.REACT_APP_CLOUD_NAME}/upload?api_key=${process.env.REACT_APP_CLOUD_API_KEY}×tamp=${timestamp}&signature=${signature}`;
const formdata=newFormData();
formdata.append('file',values);
formdata.append('cloud_name',process.env.REACT_APP_CLOUD_NAME);
formdata.append('upload_preset','ml_default');
axios.post(url,formdata);
})
.catch((error) => {
console.log('error',error);
});
Backend:
exports.persistImage = async (request, response, next) => {
try {
cloudinary.config({
cloud_name:process.env.CLOUD_NAME,
api_key:process.env.CLOUD_API_KEY,
api_secret:process.env.CLOUD_API_SECRET,
});
const signUpload=async () => {
const timestamp=Math.round((newDate()).getTime() /1000);
const params= {
timestamp,
};
const signature = cloudinary.utils.api_sign_request(
process.env.CLOUD_API_SECRET,
params,
);
return { timestamp, signature };
};
const signature= await signUpload();
console.log('signature',signature);
response.status(200).json(signature);
} catch (error) {
next(error);
}
};
I've been searching for a solution, but nothing is working for me. Please help, thanks!
-
Hi Justin,
You can follow our docs on signed uploads, we have a complete example there demonstrating how to use signatures in forms. In general, Cloudinary's SDKs take care of the signature generation where needed for communication with Cloudinary, so you will only need to manually write the code for generating a signature when NOT using our SDKs (which is great!).
If you are still having difficulties after following our docs, please open a private support ticket with your cloud name so I can take a look at our logs.
Warmest regards,
Tamara
0
Post is closed for comments.
Comments
1 comment