Click here to Skip to main content
15,911,478 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When we are uploading multiple upload files are large file size uploaded. Then we are getting error:- System.Web.HttpContext.Current.Request.Files' threw an exception of type 'System.OutOfMemoryException. In the handler file request " HttpFileCollection files = context.Request.Files".

What I have tried:

ajaxFileUploadFile: function (e) {
            try {
                debugger;
                var _data = new Array();
                _data.push({ 'name': 'action', 'value': 'uploadFile' });
                _data.push({ 'name': 'folderpath', 'value': $("#hdnfolderpath").val() });
                _data.push({ 'name': 'AssetValue', 'value': 'IM' });

                $(e).SingleFileUploader({
                    action: 'Handler/hnUploadfile.ashx',
                    fileinputid: "uploadfile1",
                    senddata: _data,
                    queueSizeLimit: 50,
                    fileSizeLimit: '900MB',
                    onSubmit: function (filename) { },
                    onSelect: function (file) {
                        $("#btnImportToDataBase").attr('disabled', true);
                        $("#btnValidateData").attr('disabled', true);
                        $("#btnUpload").attr('disabled', true);

                    },
                    onComplete: function (filename, response) {

                        if (response == 1) {
                            $("#spnChooseFile").html("Choose a file…");
                            $("#divAlertFile1").html("Error in uploading file. Sorry for inconvience. Please try again.");
                            $("#divAlertFile1").removeClass();
                            $('#uploadmediafile').attr('disabled', false);
                            $("#uploadfile1").attr('disabled', false);
                            $("#UploadLJpg").attr('disabled', false);
                            $("#divAlertFile1").addClass("alertMessage alert-danger");
                            $("#divAlertFile1").show();
                            $("#divfileuploader1").addClass("progress-bar-danger");
                            ProgressBar1.running = false;
                            $("#divfileuploader1").css('width', '100%').attr('aria-valuenow', 100);
                            $("#progressBar1").delay(2000).hide(0);

                            $("#lblfileUploadFlag").html("");
                            $("#txtfile").val("");

                            setTimeout(function () {
                                $("#divAlertFile1").hide();
                                $("#divfileuploader1").removeClass("progress-bar-danger");
                                $("#divfileuploader1").addClass("progress-bar");

                                ProgressBar1.running = true;
                                UploadFile1.initlizeFileControl();

                                $("#uploadfile1").unbind();
                                $("#btnUploadFile1").unbind();

                                $("#uploadfile1").change(function () {
                                    UploadFirstCall = false;
                                    UploadFile1.ajaxFileUploadFile("#btnUploadFile1");
                                    UploadFile1.imageChangeFile(this);
                                });

                            }, 5000);
                        }
                        else if (response == 2) {

                            $("#spnChooseFile").html("Choose a file…");
                            if (page_count == 1) {
                                $("#divAlertFile1").html("Please upload pdf of " + page_count + " page.");
                            }
                            else {
                                $("#divAlertFile1").html("Please upload pdf of " + page_count + " pages.");
                            }
                            $("#divAlertFile1").removeClass();
                            $("#divAlertFile1").addClass("alertMessage alert-danger");
                            $("#divAlertFile1").show();
                            $('#uploadmediafile').attr('disabled', false);
                            $("#uploadfile1").attr('disabled', false);
                            $("#UploadLJpg").attr('disabled', false);
                            $("#divfileuploader1").addClass("progress-bar-danger");
                            ProgressBar1.running = false;
                            $("#lblfileUploadFlag").html("");
                            $("#txtfile").val("");
                            $("#divfileuploader1").css('width', '100%').attr('aria-valuenow', 100);
                            $("#progressBar1").delay(2000).hide(0);

                            setTimeout(function () {
                                $("#divAlertFile1").hide();
                                $("#divfileuploader1").removeClass("progress-bar-danger");
                                $("#divfileuploader1").addClass("progress-bar");

                                ProgressBar1.running = true;
                                UploadFile1.initlizeFileControl();

                                $("#uploadfile1").unbind();
                                $("#btnUploadFile1").unbind();

                                $("#uploadfile1").change(function () {
                                    UploadFirstCall = false;
                                    UploadFile1.ajaxFileUploadFile("#btnUploadFile1");
                                    UploadFile1.imageChangeFile(this);
                                });

                            }, 4000);

                        }
                        else {
                            OnCompletegetfiledetails(filename, JSON.stringify(response), true)
                            $("#spnChooseFile").html("Choose a file…");
                            $("#divfileuploader1").addClass("progress-bar-success");
                            $('#uploadmediafile').attr('disabled', false);
                            $("#uploadfile1").attr('disabled', false);
                            $("#UploadLJpg").attr('disabled', false);
                            ProgressBar1.running = false;
                            $("#divfileuploader1").css('width', '100%').attr('aria-valuenow', 100);
                            $("#progressBar1").delay(2000).hide(0);

                            var data = jQuery.parseJSON(JSON.stringify(response));
                            setTimeout(function () {
                                $("#divAlertFile1").removeClass();
                                $("#divAlertFile1").html(data.assetfiles + ' is ' + "Uploaded");


                                //                                $("#divAlertFile1").html(data.uploaded_file_name + ' is ' + "Uploaded");
                                $("#divAlertFile1").addClass("alertMessage fileuploadsuccess");
                                $("#divAlertFile1").show();

                                $("#divfileuploader1").removeClass("progress-bar-success");
                                $("#divfileuploader1").addClass("progress-bar");

                                ProgressBar1.running = true;
                                UploadFile1.initlizeFileControl();

                                $("#uploadfile1").unbind();
                                $("#btnUploadFile1").unbind();

                                $("#uploadfile1").change(function () {
                                    UploadFirstCall = false;
                                    UploadFile1.ajaxFileUploadFile("#btnUploadFile1");
                                    UploadFile1.imageChangeFile(this);
                                });

                            }, 2000);
                        }

                    }
                });
            }
            catch (Error) {
            }
        }
    }


C# handler code:-


 HttpFileCollection files = context.Request.Files;
                    for (int i = 0; i < files.Count; i++)
                    {
                      //  Thread.Sleep(3000);
                        HttpPostedFile fileToUpload = files[i];
}
Posted
Updated 9-Mar-17 0:18am
v2
Comments
F-ES Sitecore 8-Mar-17 6:59am    
Have you googled the error and followed any possible solutions?
Sunil Badyal 8-Mar-17 7:26am    
yes i have googled and i don't have any possible solution. Please help
F-ES Sitecore 8-Mar-17 7:39am    
If we don't know what you've already tried it's hard to give an answer
Richard MacCutchan 8-Mar-17 7:04am    
The obvious answer - use less memory.
Sunil Badyal 8-Mar-17 7:23am    
Actually,we need to Upload large files size and Upload files in the bulk.So how we can use less memory.

1 solution

It would be better using FTP protocol rather than HTTP to upload large sized files. It has obvious benefits of handling large files. The web page handling the file should internally use the FTP commands to upload the file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900