0

I want to save an image on a server by sending its properties via ajax.. In the JS I'm encoding the image in base64 before I send it (along with other parameters i need):

    $.ajax({
            type: 'POST',
            url: 'PhotoSelect.aspx/GetData',
            data: JSON.stringify({ action: "save", x: x, y: y, width: width, height: height, type: type, obj_id: obj_id, image: image, team: teamVal, jersey: jerseyVal, spot: spotVal }),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json'
})

And i receive the request on server side by:

[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static JsonReturn GetData(string action, string x, string y, string width, string height, string type, string obj_id, string image, string team, string jersey, string spot)
{
//Process Image
}

Now the weird part is that this works (by this i mean it reaches the GetData function) for some images! When i attempt to send a smaller (or lower quality) image this works. When i attempt to send images that have really long base64 strings it doesnt reach the function..

Can anyone think of anything that might be wrong with this?

5
  • Could you look in the browser's console and check for any javascript error? The HTTP specification does not have any size limit or something like that. However it is a specification, not a brazilian law. Commented Jul 21, 2014 at 22:04
  • 1
    I suspect you've hit the default maxRequestLength. Try increasing it: stackoverflow.com/a/288675/14357 Commented Jul 21, 2014 at 22:06
  • Why are you base64 encoding anyway? Use blobs and upload them directly: html5rocks.com/en/tutorials/file/xhr2/#toc-sending Commented Jul 21, 2014 at 22:10
  • Thank you all for your prompt replies guys! @gustavodidomenico There is no javascript error.. I just get a Internal Server Error 500 due to the fact that it doesnt even find my GetData server side function.. Commented Jul 22, 2014 at 7:58
  • @spender I will try to change the maxRequestLength and see how it goes.. To be honest im quite new at this, i've never worked with uploading images via javascript before. I found that i could do this via base64 and thats what I attempted to do! I will also try to implement your blob suggestion as well and ill come back to you! Again thank you guys for your help.. Commented Jul 22, 2014 at 8:01

1 Answer 1

2

Thank you guys for your suggestions... for any others that might look for a solution:

You have to increase the maxJSONLength by adding this in your web.config

<system.web.extensions>
   <scripting>
     <webServices>
        <jsonSerialization maxJsonLength="50000000"/> <!-- Set the maximum request size  (the value is in KB here) -->
     </webServices>
   </scripting>
</system.web.extensions>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.