-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Binary retrieval - *Best practice* recommendations...
PostPosted: Fri Feb 20, 2004 11:19 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
Hi,
I have a table in postgreSQL, ver. 7.4.1, which serves up image data(JPEG) to users browsers. In various posts I have read there has been a favour towards storing image data as bytea (byte[]) instead of storing the filesystem location of the image, or whatever binary data is, in the database. I have decided to store my images on the database and wanted to know what *best practice* performance tweaks you suggest I make to hibernate in terms of minimising the time it takes to serve binary data to users?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 11:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I would probably rather use a property of blob type, and connect the blob read stream directly to the servlet output stream of the servlet serving the query.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 3:29 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Quote:
I would probably rather use a property of blob type

Unfortunately blobs are a major pain in postgres. I'm using BYTEA type (byte[]) because of that.

Um...best practices? Dunno. The BYTEA type is limited in size, but I think the limit is in the gigabyte range. So con't store huge images. :) Other than that, I'm not sure what you're looking for.

Check here for an example I previously posted on reading the data:
http://forum.hibernate.org/viewtopic.php?t=927911

Here's a servlet doGet() method that outputs the same data, assuming it's a png:

Code:
public void doGet(
                  HttpServletRequest req,
                  HttpServletResponse resp
                 )
           throws ServletException,
                  IOException {
                 
    Long id = new Long(req.getParameter("graphic_id"));

    try {
   
        Session session = <get your hibernate session here>

        Graphic graphic = session.load(Graphic.class, id);

        if(graphic == null) {
            resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
        } else {
            resp.setContentType("image/png");

            OutputStream out = resp.getOutputStream();

            out.write(graphic.getData());

            out.flush();
            out.close();
        }
       
    } catch(HibernateException he) {
        throw new ServletException("OOPS!", he);
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.