gpt4 book ai didi

c# - 无法使用ajax jquery post上传大型csv文件| ASP MVC

转载 作者:行者123 更新时间:2023-12-03 04:21:23 26 4
gpt4 key购买 nike

我有这段代码,可以帮助用户上传 csv 文件并使用批量上传将其放入 SQL SB 中。当我上传大小为 30 MB 的 csv 文件时,我能够在本地 m/c 和 azure 环境中成功运行此程序。没有错误,运行良好。

当我尝试仅在 azure env 中上传大于 30 MB 的文件时,出现“未找到”错误。任何文件大小都可以在本地 m/c 中正常运行。

我在行 - $("#actionOP").text(err.statusText); 得到错误结果;甚至在点击 Controller 之前。我做错了什么?

cshtml代码:

<input id="postedFile" type="file" accept=".csv" />
<button onclick="UpClaims();">Upload as Claims Data</button>
<script type="text/javascript" language="javascript">
function UpClaims() {
if (window.FormData !== undefined) {

var fileUpload = $("#postedFile").get(0);
var files = fileUpload.files;
// Create FormData object
var fileData = new FormData();
// Looping over all files and add it to FormData object
for (var i = 0; i < files.length; i++) {
fileData.append(files[i].name, files[i]);
}

$("#divProcessing").show();
$.ajax({
url: '@Url.Action("UploadClaimsFile", "Home")',
type: "POST",
cache: false,
contentType: false, // Not to set any content header
processData: false, // Not to process data
data: fileData,
success: function (result) {
$("#divProcessing").hide();
$("#actionOP").text(result);
$('#postedFile').val("");
},
error: function (err) {
$("#divProcessing").hide();
$("#actionOP").text(err.statusText);
$('#postedFile').val("");
}
});
} else {
alert("FormData is not supported.");
}
}
</script>

Web.config:

<httpRuntime targetFramework="4.5.2" maxRequestLength="2147483647" executionTimeout="99999" requestLengthDiskThreshold="2147483647"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>

最佳答案

使用的方法是将大文件分成小块。关于此解决方案的以下文章

Upload large files to MVC / WebAPI using partitioning

The approach used is to break a large file up into small chunks, upload them, then merge them back together on the server - file transfer by partitioning. The article shows sending files to an MVC server from both a webpage using JavaScript and a Web-form httpclient, and can be implemented using either MVC or WebAPI.

关于c# - 无法使用ajax jquery post上传大型csv文件| ASP MVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48423495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com