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?

diabolo
  • 21
  • 4
  • 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. – gustavodidomenico Jul 21 '14 at 22:04
  • 1
    I suspect you've hit the default `maxRequestLength`. Try increasing it: http://stackoverflow.com/a/288675/14357 – spender Jul 21 '14 at 22:06
  • Why are you base64 encoding anyway? Use blobs and upload them directly: http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-sending – spender Jul 21 '14 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.. – diabolo Jul 22 '14 at 07: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.. – diabolo Jul 22 '14 at 08:01

1 Answers1

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>
diabolo
  • 21
  • 4