0

I'm having some issues trying to upload a zip file using jquery and Asp MVC.

My upload works fine as long as I select a single text, img, bin or just about any other single file, but when I try and upload a zip I get a 404 on the Controller call

 [HttpPost]
    public ActionResult UploadFiles()
    {
        for (int i = 0; i < Request.Files.Count; i++)
        {
            var file = Request.Files[i];
            var fileName = Path.GetFileName(file.FileName);                
        }
        return Json("success", JsonRequestBehavior.AllowGet);
    } 

$(document).ready(function () {
        $('#btnUpload').click(function () {            
            // Checking whether FormData is available in browser  
            if (window.FormData !== undefined) {

                var fileUpload = $("#FileUpload").get(0);
                var files = fileUpload.files;

                // Create FormData object  
                var fileData = new FormData();

                // Looping over all files and add it to FormData object  
                for (var i = 0; i < files.length; i++) {
                    fileData.append(files[i].name, files[i]);
                }

                $.ajax({
                    url: '/File/UploadFiles',
                    type: "POST",
                    contentType: false, // Not to set any content header  
                    processData: false, // Not to process data  
                    data: fileData,
                    success: function (result) {
                        alert(result);
                    },
                    error: function (err) {
                        alert(err.statusText);
                    }
                });
            } else {
                alert("FormData is not supported.");
            }
        });
    });
Jesse
  • 1,846
  • 2
  • 22
  • 32
  • 1
    By chance, is the zip file significantly larger than the other files you've been testing? .NET has a few mechanisms for limiting the maximum upload file size. – Cᴏʀʏ Jul 11 '17 at 22:40
  • I tried a smaller file so appears my changes to up the limit didn't work properly. You are correct sir. Thanks! – Jesse Jul 11 '17 at 23:04
  • 1
    I had to actually up the limit in two places as show by this question. https://stackoverflow.com/questions/288612/how-to-increase-the-max-upload-file-size-in-asp-net – Jesse Jul 11 '17 at 23:08

1 Answers1

0

Please add the uploaded file size in configuration tag of webconfig file to avoid this issue. Bydefault that is 30MB .

 <configuration>
  <system.web>  
  <httpRuntime maxRequestLength="size in bytes/maxAllowedContentLength" />
  </system.web>
 </configuration>