I would recommend anyone to think carefully of the pros and cons of
each way and then decide carefully what you need for your specific
application.
some things that come to my mind:
pros (of storing images in the database vs. images on the filesystem):
* atomicity & concurrency: the database will make sure, that the
image and its related data always exist and are in sync
if you store only the reference of the file in the database and
the file itself on the filesystem you will have to take care of
special cases:
* storing the file was ok , but the database entry failed: if
this happens frequently, you'll have loads of unrefernced files
lingering around
* storing the db-entry was ok, but the file could not be saved on
the filesystem: in this case your buissneslogic must take care of this
issue to prevent errors
* easier backup:
* simply run a db-dump and you have all data backed up and you are
sure that it is consistent:
if you did this with the filesystem approach you would have to
backup the db-dump and the images-directory - which would bring you
synchronisation problems again
* single security realm:
both the imagedata and its related data can take full advantage of
the databases security system
* accessing the data may be easier: e.g.. when you use hibernate, you
could store a reference to the file in the user-entity
cons:
* increased network traffic - as described before (but this would
also be true, if you decide to store the images on another machine's
filesystem, wouldn't it?)
* database needs to be able to handle big amounts of data well
* how does the database perform when you have a lot of data - how
much data do you expect in the first place?
* does your database support BLOB fields - does the JDBC driver
support it, .. etc.
but in the end I guess it's always a matter of taste and of your
requirements...
On Mar 13, 10:04 am, Zé Vicente <[email protected]> wrote:
> Hi,
>
> I will give you my honestly opinion. It seems that you are new on the
> subject and I can say that I have a lot of experience on that.
>
> First of all, don't store images on the database :)
>
> It is true that we can do it, but depending of what you are going to
> do, the site of your database will be 90% images and 10% data.
>
> The images are always served by httpservers, even if you retrieve it
> from the database. So if you store the images in the file system of
> your httpserver, there is no need for network usage in case your
> database is hosted in a different server.
>
> So, use the database just to store the path of your images. Then in
> GWT, retrieve the object or list of objects that contains the path for
> your images. Again in GWT, Create an Image object and set the src
> property.
>
> That is all you need to do to display the image.
>
> What do you think?
>
> Regards,
> José Vicente
>
> On Mar 13, 2:52 am, Itamar Ravid <[email protected]> wrote:
>
> > Don't forget however to set the content type on the response to an image of
> > some type, otherwise the client's browser will try to download the picture
> > rather than display it.
>
> > On Fri, Mar 13, 2009 at 2:28 AM, gregor <[email protected]>wrote:
>
> > > I think Itamar is right, Jack, you should use a standard HttpServlet
> > > for this, not GWT-RPC, because this sends the image over to the
> > > browser as byte steam, and I don't think RPC can do that.
>
> > > First, I take it these are not images used in your UI (like icons
> > > etc), 'cos those should go in an ImageBundle. I assume you know that &
> > > these images are downloaded as user selections etc.
>
> > > 1) Consult your MySQL docs/forum to find out how to obtain an
> > > InputStream for the image via JDBC. You want to pass an InputStream
> > > back to your image download HttpServlet. You don't want to read out
> > > the image bytes yet.
>
> > > 2) You write the HttpServlet something like this example (there are
> > > lots of others around):
>
> > >http://snippets.dzone.com/posts/show/4629
>
> > > Notice that the key is a looping read of the InputStream (which you
> > > got from MySQL) that writes straight into the HttpServlet's response
> > > OutputStream. Notice also it uses a buffer byte[] array. This is so
> > > that your web server does not get it's memory clogged up with big
> > > image byte arrays - the image bytes just get shunted from the DB
> > > straight out to the browser via this buffer. Therefore set this buffer
> > > small. Apache tend to use 2048 bytes. I think Oracle prefer 4096. That
> > > sort of size for the buffer. Take care to set the response content
> > > type so the browser knows what it's dealing with.
>
> > > 3) In your client you can set the Image widget's URL to your image
> > > download HttpServlet adding a parameter for the image id.
>
> > > regards
> > > gregor
>
> > > On Mar 12, 8:54 pm, "[email protected]"
> > > <[email protected]> wrote:
> > > > Hi,
>
> > > > I'm not too sure how to implement a HTTPServlet. Does anyone know how
> > > > to use images using RPC?
>
> > > > Im really stuck on this.
>
> > > > On Mar 12, 8:43 pm, Itamar Ravid <[email protected]> wrote:
>
> > > > > The best way, IMO, is to not use GWT-RPC, but rather implement an
> > > > > HttpServlet, that retrieves the data from the database and returns it
> > > with
> > > > > the appropriate Content-Type in response to a GET http request. Then,
> > > you
> > > > > simply place an image in your GWT code, with its source being the path
> > > to
> > > > > the servlet (defined in your web.xml), passing along any parameters
> > > required
> > > > > - such as the ID of the image in the database.
>
> > > > > On Thu, Mar 12, 2009 at 12:59 PM, [email protected] <
>
> > > > > [email protected]> wrote:
>
> > > > > > Hi,
>
> > > > > > I am new to loading images into GWT from MySQL and am abit lost on
> > > the
> > > > > > best way to do it.
>
> > > > > > I already have my image in the database. How do I retrieve it? I
> > > > > > read
> > > > > > somewhere that it can just be stored as a String. Is this correct?
> > > > > > So
> > > > > > my code on the server side would look like:
>
> > > > > > //Open database connection
> > > > > > dc.openConnection();
> > > > > > resultSet = dc.statement.executeQuery(SELECT CategoryImage FROM
> > > > > > itemcategory_table WHERE ItemType = 'Test');
>
> > > > > > while(resultSet.next()) {
> > > > > > String test = resultSet.getString(1);
> > > > > > }
>
> > > > > > dc.closeConnection();
>
> > > > > > Or have I got this completely wrong?
>
> > > > > > Next, I need to send this over to the client. What is the best way
> > > > > > to
> > > > > > send an image over from the server to the client and how should it
> > > > > > be
> > > > > > stored?
>
> > > > > > Any help on how to use images would be much appreciated!
>
> > > > > > Regards,
> > > > > > Jack
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---