0

I am having an hybrib application in that in that a simple php page will open which contents some link of files, and from my android wrapper i have implemented the download functionality of file.

So for user convenience i am showing the length and progress of download while the file is downloading for that my application server has set a content-length header to pass the size on device, but the problem I am facing is surprising. The file length is working fine in Android 2.2. I am getting the content header correctlt but in Android 2.3 above I am getting the content length for smaller files but for the larger file I am not even getting the Header Field.

con.getHeaderField("content-length");

returning me null in case of Android 2.3 above.

So is there any limitation of size for the User Agent above 2.3 because if it is working fine in 2.2 means there is no problem at server end it is the problem only on device user agent.

Update

I have tried it with different size of files and it is working fine till 60KB in Android 2.3 above as well.

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111

1 Answers1

0

It sounds like the client may be chunking the file. Check for the presence of the following header:

Transfer-Encoding: chunked

If that exists, the request is chunked and you will not get a Content-Length header.

See http://en.wikipedia.org/wiki/Chunked_transfer_encoding for more details.

EJK
  • 12,332
  • 3
  • 38
  • 55
  • I found a post: http://stackoverflow.com/questions/11472997/using-php-to-opening-live-audio-stream-on-android, that claims chunked encoding in Android was first supported in 2.3. – EJK Jan 16 '13 at 19:35
  • FWIW, the advantage of chunked encoding would be a faster upload and the client does not have to read the entire file. Instead it can stream the file. The downside of this is that the file size is not indicated up-front so you cannot easily display upload progress. – EJK Jan 16 '13 at 19:37
  • then why I am getting the header for smaller length of files. – Piyush Agarwal Jan 16 '13 at 19:45
  • Probably an optimization. I am guessing that chunking kicks in at some threshold. For small files, chunking does not save much time. For larger ones it does. – EJK Jan 16 '13 at 19:56
  • i have checked with different size of files and it is working fine for file less than 60KB in Android 2.3 above as well. – Piyush Agarwal Jan 16 '13 at 20:02