Length of stream returned from Android browser is always -1

Hi, after getting the input stream from getURLResult().getInputStream(), getTotalLength() (and getNumBytesRemaining() ) both return -1.


1 Like

Hi, thx. I was raising it more for the fact that this might be a bug as we’re still working through some issues in the browsers.

If it really isn’t possible to get the size of a file on Android then maybe that should be explicitly documented?

It’s not a file, it’s a URL, and this isn’t Android specific.

It shouldn’t be a surprise that you can’t know the size of file that a remote server will give you until you’ve contacted the server and started reading it, and it may not be known at all if the server doesn’t provide the size in its header response.

ok, I thought it was Android specific as the same code returns a valid size for the URL that references the same file on GoogleDrive accessed from iOS.

What you say makes sense, but I was thinking more from the point of, if it works on iOS it might be a bug in the Android code. Thinking about it, doesn’t iOS download everything locally first so you end up referencing a local file in reality? Guess that would explain the behavioural difference

Sure, thanks for looking out for bugs! I don’t really know anything about the internals of the thing that’s returning that URL, but regardless of which platform you’re on, -1 is unfortunately just a valid result that your code needs to be prepared to handle!