gpt4 book ai didi

c# - 将 base64 从 javascript 传递到 C# 服务器函数

转载 作者:行者123 更新时间:2023-12-02 17:10:17 25 4
gpt4 key购买 nike

我想通过 ajax 发送图像属性来将图像保存在服务器上。在 JS 中,我在发送图像之前将图像编码为 base64(以及我需要的其他参数):

    $.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'
})

我通过以下方式在服务器端收到请求:

[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
}

现在奇怪的是,这对某些图像有效(我的意思是它到达了 GetData 函数)!当我尝试发送较小(或较低质量)的图像时,此方法有效。当我尝试发送具有很长的 base64 字符串的图像时,它无法到达该函数..

有人能想到这可能有什么问题吗?

最佳答案

感谢你们的建议...对于任何可能寻找解决方案的其他人:

您必须通过在 web.config 中添加此值来增加 maxJSONLength

<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/> <!-- Set the maximum request size (the value is in KB here) -->
</webServices>
</scripting>
</system.web.extensions>

关于c# - 将 base64 从 javascript 传递到 C# 服务器函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24875570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com