我在MVC.NET Core应用程序中上传大文件时遇到问题。无论我做什么,我都会返回404无数据响应
这是我上传文件的任务方法
[RequestSizeLimit(40000000)]
public static async Task<string> UploadAttachment(string bis232JsonString, string url, string formType, string token, long maxResponseContentBufferSize)
{
var result = "Error";
try
{
// To Do : Use ConfigurationManager.AppSettings["endpoint"];
string endpoint = $"{url}/{formType}Attachment/post";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//client.MaxResponseContentBufferSize = maxResponseContentBufferSize;
using (var request = new HttpRequestMessage(HttpMethod.Post, endpoint))
{
request.Content = new StringContent(bis232JsonString, Encoding.UTF8, "application/json");
using (var response = await client.SendAsync(request))
{
if (response.IsSuccessStatusCode && (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.NoContent))
result = "Success";
else
result = "Error";
}
}
}
}
catch (Exception ex)
{
//to do : Log application error properly
result = "Error";
}
return result;
}
我尝试了以下
尝试如下所示全局更新上传限制
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 52428800; });
但是,无论我尝试做什么,似乎都没有效果
请让我知道是否有什么办法可以使它起作用