I am trying to upload an mp4 video file that is 5.25 MB in size in an ASP.NET MVC 5 application.
I have tried adding this to the Web.config file which has been the accepted answer in most cases to this problem.
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" />
</system.web>
I've also tried setting the timeout as well in the Web.config
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
However, when I go to upload the file I am getting System.Web.HttpException (0x80004005): Maximum request length exceeded.
Maybe there is something that needs to be set in the controller or view?
Controller:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
if (fileName != null)
{
var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
View:
@using (Html.BeginForm("Edit", "Posts", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" />
<input type="submit" value="OK" />
}
How do you upload video files in ASP.NET MVC 5?
Try add this in web.config (in bytes !):
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
</system.webServer>