多部分表单数据请求无法调用大文件大小
Multipart Form Data Request Failing to Call For Large File Sizes
我有一个文件上传功能,它采用多部分形式的数据请求并将文件放在 AWS 中。 IT 对小文件工作正常,但当文件变得非常大时就会失败。 (还没有测试到底有多大,但我们希望能够处理任何尺寸)。
这是我用来测试上传的 Linqpad 脚本:
const string filePath = @"C:\Users\josh.bowdish\Pictures\SmallFile.png";
const string contentType = "image/png";
//const string filePath = @"C:\Users\josh.bowdish\Pictures\ReallyBigFile.mp4";
//const string contentType = "video/mp4";
using (var httpClient = new HttpClient())
{
MultipartFormDataContent form = new MultipartFormDataContent();
var bytes = File.ReadAllBytes(filePath);
form.Add(new ByteArrayContent(bytes)
{
Headers =
{
ContentLength = bytes.Length,
ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType)
}
},"notused","not.used");
using (var response = await httpClient.PostAsync("http://localhost:52655/api/Storage/UploadAttachment", form))
{
response.EnsureSuccessStatusCode();
response.Content.Dump();
}
}
SmallFile.png 上传正常,但 ReallyBigFile.mp4 甚至没有访问我的本地服务。它确实给我带来了 404 错误,这对我来说没有意义,因为服务端点没有改变。
我会 post 接收方法的代码 (api/Storage/UploadAttachment),但是尝试用大文件调用它甚至没有在方法调用中到达我的第一个断点。
到目前为止,我的谷歌搜索工作还没有得到多少回报。任何指导将不胜感激!如果我可以提供任何其他帮助解决问题,请告诉我!
谢谢,
~乔希
如果您在较大的文件上收到 404 而不是较小的文件,请确保您的网络配置设置允许大文件:
<!-- maxRequestLength in kilobytes -->
<system.web>
<httpRuntime maxRequestLength="1000000" />
</system.web>
<!-- maxAllowedContentLength in bytes -->
<system.WebServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1000000000" />
</requestFiltering>
</security>
</system.WebServer>
我有一个文件上传功能,它采用多部分形式的数据请求并将文件放在 AWS 中。 IT 对小文件工作正常,但当文件变得非常大时就会失败。 (还没有测试到底有多大,但我们希望能够处理任何尺寸)。
这是我用来测试上传的 Linqpad 脚本:
const string filePath = @"C:\Users\josh.bowdish\Pictures\SmallFile.png";
const string contentType = "image/png";
//const string filePath = @"C:\Users\josh.bowdish\Pictures\ReallyBigFile.mp4";
//const string contentType = "video/mp4";
using (var httpClient = new HttpClient())
{
MultipartFormDataContent form = new MultipartFormDataContent();
var bytes = File.ReadAllBytes(filePath);
form.Add(new ByteArrayContent(bytes)
{
Headers =
{
ContentLength = bytes.Length,
ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType)
}
},"notused","not.used");
using (var response = await httpClient.PostAsync("http://localhost:52655/api/Storage/UploadAttachment", form))
{
response.EnsureSuccessStatusCode();
response.Content.Dump();
}
}
SmallFile.png 上传正常,但 ReallyBigFile.mp4 甚至没有访问我的本地服务。它确实给我带来了 404 错误,这对我来说没有意义,因为服务端点没有改变。
到目前为止,我的谷歌搜索工作还没有得到多少回报。任何指导将不胜感激!如果我可以提供任何其他帮助解决问题,请告诉我!
谢谢,
~乔希
如果您在较大的文件上收到 404 而不是较小的文件,请确保您的网络配置设置允许大文件:
<!-- maxRequestLength in kilobytes -->
<system.web>
<httpRuntime maxRequestLength="1000000" />
</system.web>
<!-- maxAllowedContentLength in bytes -->
<system.WebServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1000000000" />
</requestFiltering>
</security>
</system.WebServer>