tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Don Albertson <Don.Albert...@verizon.net>
Subject Re: Read image from database
Date Wed, 11 Apr 2007 16:14:05 GMT
Kris Schneider wrote:
> Don Albertson wrote:
>> Zilberstein Yuval wrote:
>>
>>> Hello,
>>> Can anyone tell me how do I read an image from a Blob field in the
>>> database?
>>> TX
>>> YuvalZ
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>>
>>>
>>>   
>>
>>
>> I haven't put any of this into tags but....
>>
>> My experience is limited to our Oracle system. I created two classes:
>>
>> One wraps the Oracle implementation code and avoids the need to
>> import oracle.sql.BLOB;
>> import oracle.jdbc.OracleResultSet;
>> in places that are isolated from driver implementation details
>>
>> Another converts the BLOB's to and from Image and byte[]  so I can 
>> display them.
>>
>> For the web side, I adapted a servlet to display the image using this 
>> fragment:
>>
>>                    byte[] imageData = image.getImageBytes();
>>                    if ( imageData != null && imageData.length > 0){
>>                        response.setContentType("image/jpeg");
>>                        ServletOutputStream sos = 
>> response.getOutputStream();
>>                        sos.write(imageData);
>>                    }
>>
>> I only save a thumbnail in the database as a BLOB so the thumbnail is 
>> the only image being returned in the response stream.
>
> If you're just serving the images out the database then there's 
> certainly no need to create an "intermediate" Image (like my first 
> reply) - just grab the byte[] and serve it with the proper content 
> type. If the images are unlikely to change, I'd recommend also setting 
> response headers so that the client knows it's OK to cache the images 
> and can avoid making additional requests for them.
>
    The variable "image" isn't an Image, it's an instance of a class 
that uses a BLOB and return it either as an Image or byte[].  In this 
case, no Image is ever created.  To the servlet, "image" is an interface. 

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message