Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax callback with FormData fails for large files

I've a input file control where I can upload any kind of file. So, I'm getting the file and storing in a FormData and making an ajax call to my controller. It is working fine with Images and small .mp3 files. But when I'm uploading .mp3 files more than 5MB, it is going to the error function

My code goes 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?

like image 727
RealSteel Avatar asked May 07 '15 10:05

RealSteel


1 Answers

Yeah...I found the solution.Thanks to @artm

I've changed the maxRequestLength in web.config

<httpRuntime targetFramework="4.5" maxRequestLength="2097151" />
like image 175
RealSteel Avatar answered Oct 20 '22 06:10

RealSteel