I am developing an android app and using phonegap 2.6.0 What I want to do is to download a file/folder. I want the size of file portion that is being downloaded. Any help?
Asked
Active
Viewed 985 times
1 Answers
1
check out FileTransfer.onprogress
fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
} else {
loadingStatus.increment();
}
};
fileTransfer.download(...); // or fileTransfer.upload(...);
I think what you are looking for is progressEvent.total

whodeee
- 617
- 5
- 18
-
var ft = new FileTransfer(); ft.onprogress = function(progressEvent) { if (progressEvent.lengthComputable) { var perc = Math.floor(progressEvent.loaded / progressEvent.total) * 100; } }; This is what I was trying but somehow I am getting the loaded size twice as that of the total size...Thanks in advance @whodee – madhukar kumar May 17 '13 at 07:33
-
not sure what you are doing, some of your code would be helpful to see. – whodeee May 17 '13 at 14:53
-
Sorry for my previous comment. Its working fine but what my actual need is to reflect this value continuously in a progress bar. I have tried it using jquery but it didn't work.Could please guide me thorough this? – madhukar kumar May 24 '13 at 09:35
-
what have you tried? can you show your code and we can then see what wasn't working. – whodeee May 24 '13 at 13:45
-
under the function for downloading a file from the url which i get from the server, I have written code for catching the size of file being downloaded like: var ft = new FileTransfer(); ft.onprogress = function(progressEvent) { if (progressEvent.lengthComputable) { perc = Math.floor((progressEvent.loaded / progressEvent.total) * 100); } – madhukar kumar May 27 '13 at 05:28
-
Please check the code on the link http://stackoverflow.com/questions/16774061/adding-progress-bar-for-file-being-downloaded-using-phonegap-and-jquery – madhukar kumar May 27 '13 at 13:16
-
I posted an answer to that question – whodeee May 28 '13 at 18:49