Ajax callback with FormData error for large files

I have a control input file

where I can upload a any kind

file. So I get the file and storing in a FormData

and I create ajax call

for my controller. It works great with images and small .mp3 files. But when I upload .mp3 files more than 5MB, it does the error function

My code looks like this:

 document.getElementById('fileUploadControl').onchange = function () {

        var data = new FormData();
        var files = $("#fileUploadControl").get(0).files;

        for (var i = 0; i < files.length; i++) {
            data.append("UploadedImage" + i, files[i]);
        }

        var ajaxRequest = $.ajax({
            url: '/Main/BroadcastFileUpload/',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: "POST",
            success: LoadImages,
            error: OnLogoFail
        });

        ajaxRequest.done(function (xhr, textStatus) {
        });
    };

 <input type="file" multiple id="fileUploadControl" style="width:0px;height:0px" />

      

Can anyone help me with this?

+3


source to share


3 answers


Yes ... I found a solution. Thanks @artm

I changed maxRequestLength

in web.config



<httpRuntime targetFramework="4.5" maxRequestLength="2097151" />

      

+3


source


It mainly has to do with the server side message limit. They have a default size for security concerns only. If you are using Tomcat, you can configure the connector in server.xml to set maxPostSize. Mostly 2 MB by default.



It applies to any server with ASP, JSP or PHP. Maybe the config file might be different.

0


source


document.getElementById ('fileUploadControl'). onchange = function () {

    var data = new FormData();
    var files = $("#fileUploadControl").get(0).files;

    for (var i = 0; i < files.length; i++) {
        data.append("UploadedImage" + i, files[i]);
    }

    var ajaxRequest = $.ajax({
        url: '/Main/BroadcastFileUpload/',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        type: "POST",
        success: LoadImages,
        error: OnLogoFail
    });

    ajaxRequest.done(function (xhr, textStatus) {
    });
};

      

0


source







All Articles