I have a Web API 2 project which accepts file uploads. Uploading small files works pretty well, but when it comes to large files, they simply are not written to disk. It appears to me that this happens with files that are somewhere around 2 GB. Files of about 1 gb upload pretty well.
These are the relevant parts of my web.config:
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" maxRequestLength="2147483647" />
</system.web>
...
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295" />
</requestFiltering>
</security>
</system.webServer>
I got the values for maxAllowedContentLength and maxRequestLength from this answer.
Since I am running IIS 8 I would expect to meet the maxAllowedContentLength value.
And this is the Action responsible for handling the upload, based on this blog post by Filip W:
[HttpPost]
public async Task<HttpResponseMessage> Post()
{
//Check if the request contains multipart/form-data.
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string uploadPath = @"C:\temp\upload"; // in reality this is retrieved from DB
try
{
var provider = new MultipartFormDataStreamProvider(uploadPath);
var content = new StreamContent(HttpContext.Current.Request.GetBufferlessInputStream(true));
foreach (var header in Request.Content.Headers)
{
content.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
var result = await content.ReadAsMultipartAsync(provider);
return Request.CreateResponse(HttpStatusCode.Accepted);
}
catch(Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}
Uploading small files works. I see them written to c:\temp\upload. But large files are not saved, although I see them coming in (by watching Task Manager > Performance:
Does anyone have an idea why I don't see large requests saved to disk, while smaller files do get saved?