我使用JavaScript中的FileReader对象将PDF文件(不超过2页只有文本)转换为base64字符串,然后通过简单的AJAX请求将字符串传输到我的服务器(WCF)。但我收到以下错误:
413 Request Entity Too Large
所以我的Javascript + JQuery如下:
function upload() {
var file = document.getElementById("inputFile").files[0];
var fr = new FileReader();
fr.onload = function () {
var binaryString = this.result;
var objUploader = {
element: {
Name: "example",
Document: binaryString.split("base64,")[1]
}
};
$.ajax({
url: "http://localhost/Uploader/ServiceUploader.svc/saveDocument",
data: JSON.stringify(objUploader),
dataType: "json",
type: "POST",
contentType: "application/json; charset=uft-8",
success: function (data) {...},
error: function (xhr, status, error) {...}
});
};
fr.readAsDataURL(file);
}
在我的WCF web.config中,我有这个:
<wsHttpBinding>
<binding closeTimeout="00:50:00" openTimeout="00:50:00" receiveTimeout="00:50:00"
sendTimeout="00:50:00"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None"/>
</binding>
</wsHttpBinding>
有谁知道如何解决这个问题?非常感谢你!!