400 Bad Request using jQuery plugin
Hello,
I am trying to use your jQuery plugin as described in http://cloudinary.com/documentation/jquery_integration#getting_started_guide, but I get a 400 Bad Request response.
I am importing the libraries that are needed and I also do $.cloudinary.config({ cloud_name: cloudinary_cloud_name, api_key: cloudinary_api_key});
I am afraid that the issue is in my input file, this is how the input file looks like:
<input class="cloudinary-fileupload" data-cloudinary-field="image_id" data-form-data="{&quot;timestamp&quot;:1436467258,&quot;callback&quot;:&quot;https://c.cs8.visual.force.com/apex/CARY_UploadImage&quot;,&quot;signature&quot;:&quot;bd8b04aa7a86e60178243cbce85e706cd80d2571&quot;,&quot;api_key&quot;:&quot;782454775414318&quot;}" name="file" type="file">
This is how the unescaped json looks like:
{
"timestamp":1436467000,
"callback":"https://c.cs8.visual.force.com/apex/CARY_UploadImage",
"signature":"bd8b04aa7a86e60178243cbce85e706cd80xxxxx",
"api_key":"782454775414318"
}
Just in case, my cloud name is deindeal-ch.
I've been struggling to find the issue for a long time, but I cannot find the solution, could you please help me?
Thanks a lot and best regards.
-
Hi David,
It seems that the JSON you pass into
data-form-data
is double-html-escaped. Can you please html-escape it only once and try again?
It should look something like:{"timestamp":1436467258,"callback":"https://c.cs8.visual.force.com/apex/CARY_UploadImage","signature":"bd8b04aa7a86e60178243cbce85e706cd80d2571","api_key":"782454775414318"}
0 -
Hello Itay,
I have changed it, but I still get the same 400 Bad Request: this is how data-form-data looks like now:
{"timestamp":1436597748,"callback":"https://c.cs8.visual.force.com/apex/CARY_UploadImage","signature":"2f940e384bf3f2816c4c187b72f43a4d5b394fbb","api_key":"782454775414318"}Just for the record, I am using Salesforce.com in the backend and this is how I generate the signature:
cloudinary_timestamp=String.valueOf(Integer.valueOf(System.NOW().getTime()/1000));
String myData = 'public_id=CldinaryImg×tamp='+cloudinary_timestamp+cloudinary_api_secret;
Blob hash = Crypto.generateDigest('SHA1',Blob.valueOf(myData));
String hexDigest = EncodingUtil.convertToHex(hash);
cloudinary_signature = hexDigest;0 -
It seems that the
data-form-data
is now partially html-escaped and partially isn't.Can you please make sure it is all escaped once and try this again?
You can use the code snippets from our SalesForce integration KB.
0 -
Hi Itay,
sorry, for some reason when I copy&paste the data-form-data here, the escaped strings are modified:
This is the data-form-data (hope it will not be modified when I submit the answer):&
quot;timestamp&
quot;:1436767137,&
quot;callback&
quot;:&
quot;https://c.cs8.visual.force.com/apex/CARY_UploadImage",&
quot;signature&
quot;:&
quot;cd6280fd3dee31fba03a22b54bd5637ca0bb4646&
quot;,&
quot;api_key&
quot;:&
quot;782454775414318&
quot;I am using Salesforce, but I do not want to upload pictures from the salesforce server. Instead, I'd like to use jQuery to upload directly from the page without having to pass the info to the server.
0 -
If you could please open a Support ticket and attach the full generated HTML file there, I'll be happy to take a deeper look at it.
0
Post is closed for comments.
Comments
5 comments