How to know the file size when uploading via multipart form-data?

I am using a simple application with an HTML client that uploads a file to the server and should display a progress bar :)

The server is based on servlets, some servlet receives multi-page content, analyzes it, etc. Obviously, every moment I know the number of bytes received. However, in order to provide information for the progress bar on the client side, the servlet also needs the total number of bytes for the downloaded file. Any idea where to get the total number of bytes?

Thanks!

+4
source share
2 answers

The size of the content is placed in the Content-Length header (see rfc2616 ). In Servlet, you can get this request.getContentLength() or reqest.getHeaders("Content-Length") header value

+1
source

I think you need to implement a progress bar in javascript on the client side.

In any case, this link gives an explanation of how to do this using jQuery.


The server can get the size of a multi-page file loaded from the header of the HTTP request; see @ilya's answer. However, getting this information and counting the bytes read so far in the stream of HTTP responses that display or update the progress bar will be quite difficult ...

+2
source

All Articles