Java - Monitor progress of a async file downloading in server -


i have server-side application download file external url server. happens on async process. need have ajax call file download progress , report in ui.

this can achieved updating file download progress db in defined interval , ajax call can progress database. db resource intensive.

another option (i'm not sure if works) read file downloading in progress compare size total content-length % downloaded.

is there way access outputstream async background process , return upload % ?

the front end of application using angularjs , backend implemented using spring framework.

file download code generic:

// opens input stream http connection inputstream inputstream = httpconn.getinputstream(); string savefilepath = savedir + file.separator + filename;  // opens output stream save file fileoutputstream outputstream = new fileoutputstream(savefilepath);  int bytesread = -1; byte[] buffer = new byte[buffer_size]; while ((bytesread = inputstream.read(buffer)) != -1) {     outputstream.write(buffer, 0, bytesread); } outputstream.close(); inputstream.close(); 


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -