Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid signature String to sign #638

Closed
namhihi237 opened this issue Nov 30, 2023 · 2 comments
Closed

Invalid signature String to sign #638

namhihi237 opened this issue Nov 30, 2023 · 2 comments

Comments

@namhihi237
Copy link

namhihi237 commented Nov 30, 2023

Bug report for Cloudinary NPM SDK

I am use "cloudinary": "^1.41.0",

Describe the bug in a sentence or two.

Can not upload image by presigned URL, get the error Invalid signature

Issue Type (Can be multiple)

[ ] Build - Can’t install or import the SDK
[ ] Babel - Babel errors or cross browser issues
[ ] Performance - Performance issues
[ ] Behaviour - Functions aren’t working as expected (Such as generate URL)
[ ] Documentation - Inconsistency between the docs and behaviour
[ ] Incorrect Types - For typescript users who are having problems with our d.ts files
[x] Other (Specify)

Steps to reproduce

I have API return presigned url to upload

  generatePresignedUrl() {
    const { cloudName, apiKey } = this.configService.get('cloudinary');
    const timestamp = Math.round(new Date().getTime() / 1000);
    const signature = cloudinary.utils.api_sign_request({ timestamp }, apiKey);
    return `https://api.cloudinary.com/v1_1/${cloudName}/image/upload?api_key=${apiKey}&signature=${signature}&timestamp=${timestamp}`;
  }

Error screenshots

I am getting an error when posting presiged url
Screenshot 2023-12-01 at 00 23 10

Browsers (if issue relates to UI, else ignore)

[ ] Chrome
[ ] Firefox
[ ] Safari
[x] Other (Specify)
[ ] All

Versions and Libraries (fill in the version numbers)

Cloudinary_NPM SDK version
Node - v20.9.0
NPM - 10.1.0

Config Files (Please paste the following files if possible)

Package.json

Repository

If possible, please provide a link to a reproducible repository that showcases the problem

@dannyv-cloudinary
Copy link
Contributor

Hey there, thanks for getting in touch.

It seems you have an error in your code. The signature needs to be generated with the API Secret, rather than key. Could you please update your code to the following and let us know if you are then able to upload?

  generatePresignedUrl() {
    const { cloudName, apiKey, apiSecret } = this.configService.get('cloudinary');
    const timestamp = Math.round(new Date().getTime() / 1000);
    const signature = cloudinary.utils.api_sign_request({ timestamp }, apiSecret);
    return `https://api.cloudinary.com/v1_1/${cloudName}/image/upload?api_key=${apiKey}&signature=${signature}&timestamp=${timestamp}`;
  }

@namhihi237
Copy link
Author

Ah, Thanks for pointing out. It's works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants