JPG content-length or deal with chunked transfer?
843841Jun 28 2006 — edited Jun 30 2006Hi
I have to send a JPG image from a servlet to an applet, and, I have to do it through an URLConnection (the host doesn't allow doing that opening a raw socket connection). And here comes the (HTTP protocol specific) trouble. Before flushing the image from the servlet one has to know it's size in bytes to set the "content-length" property, otherwise the server sends it in "chunks", thus, my applet receives not only the image, but also the so called "chunk metadata". Hence I have 2 ways to solve the problem.
1. The easiest. To find out how many bytes occupies the JPG image and tell it to the server by setting the "content-length" property before flushing the image from the servlet to the applet.
2. Write a custom "transfer-encoding: chunked"-processing function in the applet, which would sort the bytes received and do low level bytes pushing to "put the image together", which I couldn't manage..
Thus, someone please give me a hint how to find out the byte size of a JPG image which is in the memory (or a function which puts back the data received via a "chunked" transfer). I could write the image to disk (on the server-side) then read the size of the image file and set this way the "content-length" property, but I really don't wanna do this cause it would work very slow and I think is an awkward solution..
Please help!