简体   繁体   中英

Pass base64 from javascript to C# Server function

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM