jjspierx
jjspierx

Reputation: 440

FineUploader - Error with JSON Response - "Response does not include the base64 encoded policy!"

I am trying to use FineUploader in an asp.NET MVC5 application. When I try to upload a file using FineUploader, in my Controller, I am Base64 encoding the policy document, signing the base 64 encoded document, and then returning the results as a JSON object as per the documentation. However, I am receiving the following error on my page after the Controller returns the JSON:

"Response does not include the base64 encoded policy!"

There must be something wrong with the formatting of my JSON payload. Here the relative portion of code:

byte[] byteArrayPolicy = System.Text.Encoding.UTF8.GetBytes(jsonStringFull);
        string base64Policy = Convert.ToBase64String(byteArrayPolicy);

        var signature = kha.ComputeHash(Encoding.UTF8.GetBytes(base64Policy));
        var signatureString = ToHexString(signature, true);

        string  payloadString = @"{ ""policy"":""" + base64Policy + @"""," + @"""signature"":""" + signatureString + @"""}";

        JsonResult jsonRequest = Json(payloadString);

        return jsonRequest;

Is there anything wrong with formatting of the JSON object I am returning? The policy is an exact copy of the policy I received from FineUploader, only it has been Base64 encoded. The signature is a hex string. Here is a sample of what payload looks like:

"{ \"policy\":\"eyJleH...=\",\"signature\":\"da186a017b038382e2cc21dfa4f1fbf806c51adf92984a9b95f1aa845aeb72e4\"}"

Note the "..." in the Base64 policy was for brevity.

The error I am getting says the Response does not include a Base64 encoded policy, but it appears to me that it does include the Base64 encoded policy. Is it possible my signature is incorrect? Should it not be converted to a hex string after I compute the signature as a byte array?

Here is the actual paypload, according to Chrome:

"{ \"policy\":\"eyJleHBpcmF0aW9uIjoiMjAxNi0wNC0xNFQxNDo0MzozMS4zOTZaIiwiY29uZGl0aW9ucyI6W3siYWNsIjoicHJpdmF0ZSJ9LHsiYnVja2V0IjoiZnVuZHRoZWZ1bmVyYWwifSx7IkNvbnRlbnQtVHlwZSI6ImltYWdlL2pwZWcifSx7InN1Y2Nlc3NfYWN0aW9uX3N0YXR1cyI6IjIwMCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsia2V5IjoiNGZkOGIzMDMtMmQ3Zi00MWJlLThiYWItYzUyMjBiNmRlMjQ1LmpwZyJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFKUkhDU09STExFUkpVMkVBLzIwMTYwNDE0L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWRhdGUiOiIyMDE2MDQxNFQxNDM4MzFaIn0seyJ4LWFtei1tZXRhLXFxZmlsZW5hbWUiOiIyMDE2LTAzLTI0LmpwZyJ9XX0=\",\"signature\":\"c592b3bca0dedba10301e06df37760cb527ac0a83112ae9b668dce00f0b23465\"}"

Upvotes: 0

Views: 1431

Answers (1)

Ray Nicholus
Ray Nicholus

Reputation: 19890

The error does appear to be in your code. The response payload, as you have illustrated in your answer, is this:

"{...}"

But it should be this:

{...}

After running your response through JSON.parse, the result is a single string instead of an object.

Upvotes: 1

Related Questions