Does the img.setUrl("data:image/jpg;base64,"...-trick work reliable in
all major browsers?

On 13 Mrz., 15:07, Darren <[email protected]> wrote:
> The one case that hasn't been mentioned is when one dynamically
> creates transient images on the server.
>
> We transform various XML data sources into SVG and then transcode into
> JPG (using Batik) on the fly, then base 64 encode the JPG into a
> string and send it across via GWT-RPC.
>
> Then on the client, once you have the image data from the RPC callback
> (as a String):
> String base64EncodedImage = ... ;
> Image img = new Image();
> img.setUrl("data:image/jpg;base64," + base64EncodedImage);
>
> On Mar 13, 5:08 am, stone <[email protected]> wrote:
>
> > use a servlet url for downloading img.
> > for example: myapp/dbimage/123456
> > and the servlet mapping is /dbimage/*
>
> > On Mar 13, 9: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
-~----------~----~----~----~------~----~------~--~---

Reply via email to