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").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++)
{
HttpPostedFile fileToUpload = files[i];
}