[英]Sending a file from front end to back end taking too long
我目前正在构建一个 Web 应用程序,它接受用户上传的 excel 文件(使用 Javascript),将其发送到后端(使用 C#)并在返回答案之前搜索特定字段。 到目前为止,我的代码似乎适用于小文件,但是用户将提供的文件每个大约 4MB。 当我上传该大小的文件并使用断点跟踪代码时,我意识到它甚至没有到达 C# 代码,连接似乎失败了,我相信这是因为传递文件所需的时间太长。
以下是我的 javascript 代码的一部分:
document.getElementById('selectedFile').addEventListener('change', function (event) {
var reader = new FileReader();
reader.onload = function () {
filename = event.target.files[0].name;
fileContent = btoa(new TextDecoder('utf-8').decode( new Uint8Array(this.result)));
console.log(fileContent);
}
reader.readAsArrayBuffer(this.files[0]);
},
$("#btnRunReport").on("click",
function () {
if (!validateFilename()) {
showErrorMsg("Please upload an EXCEL file with the extension .xlsx");
return;
}
var request = runReportRequest;
authorizeAndExecuteAjaxRequest(request);
}
);
function runReportRequest() {
toggleRunButton();
$("#textAreaRow").show();
var token = getUserToken();
RunMT4ConfigHub.invoke("RunReport", token, filename, fileContent);
}
所有这些代码都可以完美运行,直到发送更大的文件。 有没有办法让连接持续更长时间,或者可以分部分发送我的文件,以避免连接失败?
在您的 web.config 中添加以下内容:
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>
我认为默认情况下文件大小限制为 4mb。 (其中 xxx 是 kb)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.