ASP.NET MVC - How to upload a file with more than 5mb using ajax?

Asked

Viewed 525 times

0

I am using the following code to perform file upload:

HTML:

<form action="/Employee/FileUpload?UnityId=1&amp;ObjectId=1" data-ajax="true" data-ajax-failure="OnFailure" data-ajax-method="Post" data-ajax-success="OnSuccess" enctype="multipart/form-data" id="form6" method="post" class="MultiFile-intercepted"><div class="card default">
    <input multiple type="file" tabindex="-1" name="File" required title=" " autocomplete="off" maxlength="10" onchange="this.setCustomValidity('')" data-maxsize="10240" class="multi custom-file-input" accept=".bmp,.jpeg,.jpg,.pdf,.xls,.xlsx,.csv,.txt,.mp4,.mkv,.avi,.wmv,.mp3,.3gp,.doc,.docx">
    <input id="file" name="submit" role="button" type="submit" class="btn btn-primary validate-form upload-archive" tabindex="0" value="Enviar" />
</form>

JQUERY:

$(function () {
$("#form6").submit(function (event) {
    var dataString;
    event.preventDefault();
    var action = $("#form6").attr("action");
    if ($("#form6").attr("enctype") == "multipart/form-data") {

        dataString = new FormData($("#form6").get(0));
        contentType = false;
        processData = false;
    } else {

    }
    $.ajax({
        type: "POST",
        url: action,
        data: dataString,
        dataType: "json",
        contentType: contentType,
        processData: processData,
        success: function (data) {

        },
        error: function (jqXHR, textStatus, errorThrown) {

            alert("fail");
        }
    });
});

});

CONTROLLER:

    [HttpPost]
    public ActionResult FileUpload(string ObjectId, string UnityId, HttpPostedFileBase File)
    {
         .. Meu código
    }

With this code I am able to upload files up to 5mb, however when I try to load one of 9mb the code does not work, the controller is even called and no error message is displayed.

Is there any limit to uploading files using this method?

How can I solve this problem?

1 answer

1


This limitation is from Asp, to change just change the parameterization in your web.config file, example:

<configuration>
  <system.web>
    <httpRuntime maxRequestLength="xxx" />
  </system.web>
</configuration>
  • Perfect. That’s exactly what it was.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.