> > That way the image data gets corrupted. Isn't this information supposed
> > to be in the HTTP Headers, and not in my output?
> 
> This corruption is produced by an HTTP/1.1 transfer encoding called
> chunking. Its support is mandatory in HTTP/1.1. Which HTTP client are you
> using ?
> If you're directly talking on the socket or using a client without real
> support for HTTP/1.1, you may want to make a request using HTTP/1.0 (which
> doesn't have chunking), or set the content length of the response (in which
> case chunking will not be used).

I'm using Netscape 4.76 and Konqueror 2.1, and I tried Mozilla Seamonkey
on Windows. They all don't display the images correctly, and when I save
them to disk the files contain these "chunking" lines at start.

I also tried to set the content length, as you said, but that didn't
help: This is what's in the file before the jpeg data when I save it to
disk:
--- snip ---
HTTP/1.1 200 OK
Content-Type: image/jpeg
 
Content-Length: 108381
Date: Fri, 23 Mar 2001 17:44:30 GMT
Server: Apache Tomcat/4.0-b1 (HTTP/1.1 Connector)
--- snap ---
 

My code looks like this now (it worked with Resin, so I think it is all
right):
--- snip ---
            // now, did we get the data? if yes, copy it
            // to the response:
            if ((blob != null) && (contentType != null)) {

                response.setContentType (contentType);
                response.setContentLength ((int) blob.length ());

                ServletOutputStream out = 
                    response.getOutputStream ();

                byte b[];
                long toRead = blob.length ();
                long read = 0;
                while (toRead > 0) {
                    b = blob.getBytes (read, 
                        (toRead > 1024) ? 1024 : (int)toRead);
                    toRead -= b.length;
                    read += b.length;
                    out.write (b);
                }

                out.flush ();
                out.close ();
--- snap ---



Please have a look at this problem.

with kind regards,
Stefan Schmidt

Reply via email to