🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #15903

servlet Question: sending image to user.

#15903
From: Steve Levine
Date: Tue, 27 Apr 1999 00:00
30 lines
1959 bytes
i am writting a java servlet to give users access to an existing database
that holds document images, both tif and jpeg. i already have a java bean
that looks up the image record and grabs the blob data and stores it as a
file (and in the correct file format).  this piece works great.  the problem
that i am having is when i send the file to the user, via the
HttpServletResponse OutputStream, it either shows up as cyptic garbage in
the web browser if i am sending tif images, or if i send jpeg the picture
shows up but mangled, and also in the web browser.  and yes i am sending the
appropriate MIME types for each ("image/tif", and "image/jpeg").  i would
like the jpeg images to show up correctly in the web browser, and i would
like the tif images to show up in the Wang Image Viewer that comes with
windows (WangImg.exe).  I do actually have all extensions(.tif, .tiff, .jpg
, .jpeg) associated with the appropriate viewer
(WanImg.exe, and my web browser).  the following is the code i am using:

   // send image to user
   java.lang.String sFilePath = "blob1.jpg";
   java.io.File fFile = new java.io.File(sFilePath);
   int iSize = (int)fFile.length();

   response.setContentType("image/jpeg");
   response.setContentLength(iSize);

   java.io.FileInputStream fIO = new java.io.FileInputStream(fFile);
   byte[] buffer = new byte[iSize];
   fIO.read(buffer);
   response.getOutputStream().write(buffer);

Am i missing something or should this work?  any help would be greatly
appreciated.
Technical Details
Message-ID: <7g57ir$jvt1@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a74be4623a2ec688,start
X-Google-Attributes: gidf74b3,public
From: "Steve Levine" <slevine@ucg.com>
Subject: servlet Question: sending image to user.
Date: 1999/04/27
Message-ID: <7g57ir$jvt1@forums.borland.com>
X-Deja-AN: 471610542
Organization: UCG
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Newsgroups: borland.public.jbuilder.java.language