For loaded bytes, just show the progress bar. Just view the xhr.upload.onprogress event. The browser knows the size of the files that it should download and the size of the downloaded data, so it can provide information about the progress.
For bytes downloaded , this is a little more complicated because in this case only the browser knows the size of the bytes it receives.
The reason evt.lengthComputable is 0 , because the browser does not know how many bytes will be sent in the server request.
To do this, there is a solution, just set the Content-Length header on the server, as shown below, to get the total byte size that the browser will receive.
// prepare the response to the client. resp is the client Response var resp = HttpContext.Current.Response; // Add Content-Length of the file to headers // if the headers is not set then the evt.loaded will be 0 resp.AddHeader("Content-Length", "lengthOfYourFile");
source share