Java SDK upload resulted in invlaid signature for my partner but I am able to upload just fine
Some information: I own the cloudinary account. We use a shared Github Repo, but use two different computers. I am able to upload an image to cloudinary; however, my partner is not able to upload an image.
He keep receiving the invalid signature error whenever he tries to upload an image.
We do not know how to fix the error or know the reason for this.
Is the error cause by him not having an account on cloudinary?
We want everyone to be able to upload images.
// all the credential is saved in an env file
Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap(
"cloud_name", cloudName,
"api_key", apiKey,
"api_secret", apiSecret,
"secure", true));
Map uploadResult = null;
// imageFile is a variable name
// getFile() return the multipartfile file from a form input -- the uploaded image
if(imageFile.getFile() != null && !imageFile.getFile().isEmpty()) {
Date timestamp = new Date();
Map<String, Object> params = new HashMap<String, Object>();
params.put("timestamp", timestamp);
//getTitle() is the title input from a form
params.put("public_id", imageFile.getTitle());
//java being a folder in my account
params.put("folder", "java");
uploadResult = cloudinary.uploader().upload(imageFile.getFile().getBytes(),
params);
}
-
Hi An,
The Signature parameter is calculated based on the parameters passed as part of the upload() method plus your cloud's API Secret. Given that you mentioned the code is the same, as you're using the same code repository, that leaves the API Secret value that is part of the SDK configuration.
As a first step, I would recommend double-checking that the value of the api_secret that your partner has configured in the SDK is the right one - and specifically, that there are no leading or trailing whitespaces or characters missing from the start/end of the secret. When copying/pasting the api_secret, I've encountered cases where additional whitespace can accidentally be included before/after the api_secret string and due to that, it will cause a different signature to be generated (that is not valid) and hence the request will be rejected when it reaches Cloudinary.
The other thing to check is if the permission/path of the environment file makes it accessible to the script you're running with the Cloudinary SDK. If the file can't be found and/or read for some reason, then the credentials won't make it into the SDK configuration and the signature would effectively be signed with an api_secret of empty string which will again cause the signature to be invalid.
Please let us know how it goes.
0
Post is closed for comments.
Comments
1 comment