I m trying to upload a file using jquery, ajax, express and nodejs. Here I want to show the progress of upload. May be there is a plugin or something else. No need to post that answers. I want to study the technique behind that. So please help me if you know how to handle this. I have an ajax call to upload the file.
$.ajax({
url:'/controller/action',
//remaining parameters
});
I found this code. I think it will help you. Also you can use this plugin JQuery File Upload
this.uploadFile = function(index) {
//baseClass == this
var file = baseClass.allFiles[index];
//Creating instance of FormData
var data = new FormData();
//Adding file
data.append('uploadFile', file.file);
//Sending it with ajax
$.ajax({
url: '/',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(response) {
var message = file.element.find('td.message');
if(response.status == 'ok') {
message.html(response.text);
file.element.find('button.uploadButton').remove();
}
else {
message.html(response.errors);
}
},
xhr: function() {
var xhr = $.ajaxSettings.xhr();
if ( xhr.upload ) {
console.log('xhr upload');
xhr.upload.onprogress = function(e) {
file.progressDone = e.position || e.loaded;
file.progressTotal = e.totalSize || e.total;
//updating downloading progress for the file
baseClass.updateFileProgress(index, file.progressDone, file.progressTotal, file.element);
//updating total progress
baseClass.totalProgressUpdated();
};
}
return xhr;
}
});
};
you can use Multer to upload your file: Multer