get size of file before download from amazon s3 in android app -


i have developed app in have asynctask downloads file amazon s3 server. related files quite large sized, need show progress bar when download happens , spiral progress bar doesn't here when keeps rotating , irritates user. need use horizontal style progress bar need know size of file downloaded. know of way know file size before downloading amazon s3.

this downloading code have used..

    @override     protected void doinbackground(void... params) {          transfermanager manager = new transfermanager(access);         file file = new file(environment.getexternalstoragedirectory()+"/downloads", downfile);         filedownloaded = "/downloads/"+ downfile;         file.setwritable(true);         download down = manager.download("files", filetodown, file );         try {             down.waitforcompletion();         } catch (exception e) {             e.printstacktrace();         }          return null;     } 

'downfile' file location saving on external directory. 'filetodown' file path on server downloaded. '/downloads/' new directory have created store files on device.

i assume using code this,

        url url = new url(f_url[0]);         urlconnection conection = url.openconnection();         // getting file length         int lengthoffile = conection.getcontentlength();          // input stream read file - 8k buffer         inputstream input = new bufferedinputstream(url.openstream(), 8192); 

the method getcontentlength() return size of file.

update 1:

i checked java docs of amazon transfermanager , download class. there method , listener might useful display progress , try using them.

http://docs.aws.amazon.com/awsjavasdk/latest/javadoc/com/amazonaws/services/s3/transfer/transfer.html#getprogress()

http://docs.aws.amazon.com/awsjavasdk/latest/javadoc/com/amazonaws/services/s3/transfer/transferprogress.html

getprogress() //this return transferprogress object. see links above 

http://docs.aws.amazon.com/awsjavasdk/latest/javadoc/com/amazonaws/services/s3/transfer/transfer.html#addprogresslistener(com.amazonaws.services.s3.model.progresslistener)

addprogresslistener 

this able think set progresslistener.

update 2:

transferprogress object has bunch of informations progress of download. has bytes transferred, total bytes transferred , transfer percentage. @ methods detail.

enter image description here


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -