I am working on an uploader in ASP.NET MVC 3. I'm using the AJAX upload control (http://valums.com/ajax-upload/). When I attempt to upload a large file via IE, everything works. However, when I attempt to upload a large file via Chrome, I get an exception on the server that says "Maximum length exceeded.". I added the following configuration setting thinking that it would solve it:
<httpRuntime maxRequestLength="2147483647" executionTimeout="3600" />
That didn't solve it though. My action code looks like the following:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
string home = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "files");
if (String.IsNullOrEmpty(Request["qqFile"]))
{
string filename = string.Empty;
foreach (string file in Request.Files)
{
HttpPostedFileBase postedFile = (HttpPostedFileBase)(Request.Files[file]);
if (postedFile.ContentLength == 0)
continue;
filename = Path.Combine(home, Path.GetFileName(postedFile.FileName));
if (Directory.Exists(baseDirectory) == false)
Directory.CreateDirectory(baseDirectory);
postedFile.SaveAs(filename);
}
}
else
{
// MY PROBLEM IS IN HERE
string filename = Path.Combine(baseDirectory, Request["qqFile"]);
byte[] buffer = new byte[Request.InputStream.Length];
Request.InputStream.Read(buffer, 0, buffer.Length);
System.IO.File.WriteAllBytes(filename, buffer);
}
return Json(new { success = true }, "text/html");
}
Why can't I upload larger files via Chrome?
You can try setting the maxAllowedContentLength
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="X" />
</requestFiltering>
</security>
</system.webServer>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.