Search code examples
javahttpfilefile-transferchunked

Getting total file length when using chunked http transfers


I've written a program in Java to use chunking to download large files over http. Everything is working fine but I'd like to add a progress bar which I can't do unless I get the total length of the file. Is there any way to do this?


Solution

  • If the server provides a Content-Length header field, then that's easy. If it doesn't, then you're out of luck.

    Reasonable server implementations provide Content-Length when the content is static and has a known size. If the content is dynamically generated, then it's impossible to know the length a priori, at least without making two passes through the data.