XMLHttpRequest ::ERR_CONNECTION_RESET 同时上传大型(2 Mo & More
XMLHttpRequest ::ERR_CONNECTION_RESET while uploading large (2 Mo & More) files
>问题
我正在尝试使用 XMLHttpRequest 上传文件,它似乎仅适用于小文件(例如大小低于 2MO)。到目前为止,我尝试了很多东西,并得到了帖子末尾显示的代码。但是,无事可做;我不断收到::ERR_CONNECTION_RESET
错误。这不是代码问题,因为在 2MO 下文件被正确卸载......我忘记了什么?我知道这可能是 IIS 或 web.config 的问题,但我可以通过谷歌搜索这个问题来解决这个问题。
铬给出的错误
POST WEBSITEANDSERVICEURL/Service/MyService.asmx/UploadFilesWithAJAX net::ERR_CONNECTION_RESET
- 句柄文件选择
- x.事件.调度
- 五、把手
爪哇语
<script type="text/javascript">
$(function() {
$('#<%= files.ClientID %>').change(handleFileSelect);
});
function handleFileSelect(e) {
if (!e.target.files || !window.FileReader) return;
var fd = new FormData();
var file = document.getElementById("<%= files.ClientID %>");
for (var i = 0; i < file.files.length; i++) {
fd.append('_file', file.files[i]);
}
var xhr = new XMLHttpRequest();
xhr.open('POST', '<%= ResolveURL("~/Services/MyService.asmx/UploadFilesWithAJAX") %>', true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
};
xhr.upload.addEventListener("progress", updateProgress, false);
xhr.send(fd);
}
function updateProgress(oEvent) {
if (oEvent.lengthComputable) {
var percentComplete = oEvent.loaded / oEvent.total;
$("#progress").text(oEvent.loaded + " ON " + oEvent.total);
}
}
</script>
网页标记
<asp:FileUpload ID="files" runat="server" multiple="true" />
<br />
<table id="selectedFiles">
</table>
<span id="progress"></span>
MyService.asmx
<ScriptService()> _
<ToolboxItem(False)> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class AJAXServices : Inherits WebService
<WebMethod(EnableSession:=True)> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _
Public Function UploadFilesWithAJAX()
' Some code which work fine, I'm sure of it.
End Function
End Class
网络.config
<!-- [...] -->
<system.web>
<httpRuntime maxRequestLength="2097151" executionTimeout="180" /><!-- MAXIMUM DURING TESTING -->
<!-- [...] -->
</system.web>
<!-- [...] -->
好的,我解决了...
溶液
如果这种情况发生在其他人身上,请确保至少在您的 Web 服务中访问一次Context.Request.Files
。
因为,在我的测试中,我只是:
Public Function UploadFilesWithAJAX()
Return "RETURN SOMETHING"
End Function
但这还不够...如果我只访问 Context.Request.Files,例如:
Public Function UploadFilesWithAJAX()
Dim files = Context.Request.Files '<---- Simply adding this... make it works :|
Return "RETURN SOMETHING"
End Function
它有效。希望它对其他人有所帮助。
顺便说一句,如果有人可以通过这样做来解释我为什么它会起作用。
在您的 Web 配置中,您定义了 maxRequestLength="2097151",大约是 2mb,因此,如果您尝试上传超过 2mb 的文件,它最终会失败。
下面的示例配置(它将允许最多 2gb )
<httpRuntime maxRequestLength="2048576000" executionTimeout="300" />
相关文章:
- jsi18n-django.catogue没有'不包含任何已翻译的字符串(但是djangojs.mo包含)
- XMLHttpRequest ::ERR_CONNECTION_RESET 同时上传大型(2 Mo & More
- 带有 ng-repeat、ng-show “show more” 和延迟加载的角度指令
- GetElementby More Item
- jQuery .load() <img> no more in <a>
- 如何在表中创建Read More按钮
- “看来More"按钮后每三个底部滚动使用jquery
- Is '===' more efficient than '!=='?
- 在这种情况下,我如何使load more按钮工作
- 检查多个空值的最佳方法是什么?例如if(foo.bar.giz.mo.)X === 123)
- Google Feed API: more than one feed
- 如何修改这个read more js
- Jquery - techniques for extending 'perimeter' for mo
- Rails truncate with a 'read more' toggle
- 添加“more”;按钮
- 如何创建带有"more"的警告对话框或“;details"不重复使用的部分
- Jquery Delay and more
- BX Slider可通过Read More按钮调整自适应高度
- 根据日期(MO,TU等)更改HTML页面
- 设置“More"“Less"字体大小