如何通过ajax发送大型base64图像字符串?

我在通过ajax发送base64图像字符串时遇到问题。 当我上传小图像时,它工作正常,但当我尝试上传大图像时,它会产生错误。 实际上我正在创建一个在线可自定义的打印Web应用程序。因此,用户可以选择添加文本和图像。 我想要的是当用户按下提交按钮时,html页面的body标签内的整个数据应该通过ajax传递到我的sql server数据库。

这是图像

这是我的Mark Up

这是我的jQuery

 //Image Upload Code function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { $('#safeZone').attr('src', e.target.result); } reader.readAsDataURL(input.files[0]); } } $("#imgInp").change(function () { readURL(this); }); //Sending Content Through Ajax function savemydata() { $.ajax({ type: "POST", url: "addProductDesigns.aspx/SaveData", data: "{'text': '" + $("#body_content").html() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: Success, failure: function (response) { alert(response.d); } }); } function Success(response) { alert(response.d); } 

这是我背后的代码

 [WebMethod()] public static string SaveData(string text) { try { string connectionString = "server=(localhost); Initial Catalog=databaseName; uid=username; password=password"; SqlConnection cnn = new SqlConnection(connectionString); SqlCommand cmd; cmd = cnn.CreateCommand(); cnn.Open(); cmd = cnn.CreateCommand(); cmd.CommandText = "insert into tempCheck values('" + text.Trim() + "')"; cmd.ExecuteNonQuery(); cnn.Close(); return "Saved Successfully"; } catch { return "Error Occurred"; } } 

当我上传小图片时它工作正常,但如果我上传大尺寸的图像它会产生错误。 请帮我。

任何帮助都会受到高度尊重。

有点晚了但希望这有助于某人在你的web.config文件中通过在配置级别添加此代码来增加maxJsonLength

        

该值等于50mb。