Currently, I am focusing on implementing file upload functionality. I have developed a code snippet using an ajax call that works flawlessly when uploading files (GB) from my local server.
$.ajax({
type: "POST",
url: "process/uploadFlatFile.htm",
enctype : 'multipart/form-data',
//timeout: 0,
crossDomain: true,
data : formData,
processData: false,
contentType: false,
cache: false,
dataType: 'json',
xhr: function() {
myXhr = $.ajaxSettings.xhr();
//myXhr = new XMLHttpRequest();
console.log("myXhr: " + myXhr.upload);
if(myXhr.upload){
console.log("adding progress event listener");
myXhr.upload.addEventListener('progress', showProgress, false);
} else {
console.log("Upload progress is not supported.");
}
return myXhr;
},beforeSend: function(xhr, opts) {
console.log("beforeSend:xhr: " + xhr + ", opts: " + opts);
currXhr = xhr;
showProgressBar();
status.empty();
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
$(cancelSelector).removeAttr('disabled');
},
success: function(result,status,xhr) {
console.log("success:result: " + result);
console.log("success:status: " + status);
console.log("success:xhr: " + xhr);
var percentVal = '100%';
bar.width(percentVal);
//$("#fountainGG").hide();
percent.html(percentVal);
$.unblockUI({
onUnblock: function(){
if(result=="success"){
console.log("SUCCESS PART :")
alertMessage("Success","File Uploaded Successfully","info");
setTimeout(function(){
window.location.href = "processFlow.htm";
//newProcessClicked('yes'); closeConDiv()
}, 2000);
}else{
alertMessage("Error","Error in upload. Try Again !","info");
}
}
});
},
complete: function(xhr,status){
console.log("COMPLETE PART :")
console.log("complete:status: " + status + ", xhr: " + xhr);
$('#btnGoUpload').prop('disabled', false);
},
error: function(xhr, statusText, err) {
$.unblockUI();
console.log("statusText: " +statusText);
console.log("error: " + err);
var msg = "Error in uploading file. Try Again !";
if (err == "abort"){
msg = "File upload aborted.";
}
alertMessage("Error",msg,"info");
}
});
However, when attempting to upload GB-sized files (above 30 Gb) from a public server, the ajax call encounters errors after a few attempts. I suspect this may be due to a connection timeout issue. If it is indeed a connection timeout problem, how can it be resolved?