1

我尝试将画布数据作为图像发送,但是当图像很大时,它不会发送数据,所以我尝试作为表单数据发送,但我被困在接收代码中。代码隐藏作为 htmlinputelementobject 接收。我怎样才能收到它?有人可以帮忙吗。

html:

var data = canvas.toDataURL("image/png");
    data = data.substr(data.indexOf(',') + 1).toString();
var dataInput = document.createElement("input");
    dataInput.setAttribute("name", "imgdata");
    dataInput.setAttribute("value", data);
    dataInput.setAttribute("type", "hidden");
var myForm = document.createElement("form");
    myForm.appendChild(dataInput);

阿贾克斯:

$.ajax({
    url: "HTML5Camera.aspx/Upload",
    type: "POST",
    // data : $('form').serialize(),
    data: "{ 'image': '" + data1 + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data, status) {
        alert('success')
    }
});

代码隐藏:

[WebMethod(EnableSession = true)]
    public static string Upload(string image)    

    {

    }
4

2 回答 2

0

尝试在 web.config 中调整请求限制:

<system.web>
    ...
    <httpRuntime maxRequestLength="8192" ... />

这里以 8 mb 为例(...表示文件/标签中可能包含的其他信息)。所有 base-64 编码文件的大小都增加了 33%,在设置最大限制时需要考虑这一点。

(当您将示例复制到帖子中时可能会出现错误,但未data1在任何地方定义,请参考 ajax 方法)。

更新完整性(来自评论):

<system.web.extensions> 
  <scripting> 
    <webServices> 
      <jsonSerialization maxJsonLength="2147483647"/> 
    </webServices>
  </scripting> 
</system.web.extensions> 
于 2015-03-03T07:26:30.977 回答
0

这是在 web.config 中增加 json 序列化的代码

代码:

 <system.web.extensions>
 <scripting>
 <webServices>
    <jsonSerialization maxJsonLength="2147483647"/>
 </webServices>
 </scripting>
 </system.web.extensions>
于 2015-03-03T17:03:28.840 回答