Get upload file count
Pregunta
I am using jquery uploader from here and I would like to know how do I get the total number of files has been added and not uploaded.
There is no specific documentation on the new version so can anyone say me how do I do this?
As I need to get this way "uploading 1 of n files
"
Here in the documentation says:
$('#fileupload').bind('fileuploadadded', function (e, data) {
//Here I need to get the upload count.
});
And If I as shown below it gives me count as 1
var totalfiles = data.files.length;
alert(totalfiles);
Solución
Following the documentation there's an event called 'fileuploadadd' that will fire every time a file has been added to the queue, so you could create a counter and increment it when the event is called.
var filestoupload =0;
$('#fileupload').bind('fileuploadadd', function (e, data) {
filestoupload++;
});
Otros consejos
Get upload file count before upload.
$('#fileupload').fileupload({
...
change: function (e, data) {
var idx=0;
$.each(data.files, function (index, file) {
idx++;
});
alert(idx);
}
...
});
I use this way to count files uploaded and total file in fileupload jquery
var uploadedFileCount = 0;
var totalFileCount = 0;
$("#fileupload").fileupload({
dataType: 'json',
url: url,
autoUpload: true,
done: function (e, data) {
//Some code
uploadedFileCount = uploadedFileCount + 1;
$("#UploadCount").html(uploadedFileCount + " of" + totalFileCount);
}
}).on('fileuploadadd', function (e, data) {
totalFileCount = totalFileCount + 1;
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow