How image stored in database could be displayed

93 views
Skip to first unread message

Sunita Mittal

unread,
Jun 7, 2007, 1:01:28 AM6/7/07
to Google-We...@googlegroups.com
Hello,

     Currently the way we can make image is using the url and loading the image from defined url.

     But suppose , if I have a image stored in database and want to send the byte[] to client and show the image by making a temp file at client side. How it can be achived.

    Or any other way We can manage showing image stored in database (i.e. binary or BLOB data).

Thanks
Sunita Mittal.



George Georgovassilis

unread,
Jun 7, 2007, 3:58:38 AM6/7/07
to Google Web Toolkit
While this has nothing to do with GWT, here is a link [1] to an
example of a servlet that can stream images from a file - the file is
the byte[] source and it's then written to the request. You'd probably
only change the source, that is get the byte[] from querying a
database.

[1] http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/Q_21986929.html

On Jun 7, 8:01 am, "Sunita Mittal" <sunita.mit...@daffodildb.com>
wrote:

Ibmurai

unread,
Jun 7, 2007, 4:26:02 AM6/7/07
to Google Web Toolkit
An easy way to accomplish this is to make a php file which sets the
headers and such...
Then you call the php file with an image id or whatever and it returns
the image you want....
Example:
Image = new Image("www.somepage.com/image.php?id=42");

I'm sure there's lots of examples out there on how to make the php
file - it's easy though... In my project I've done it with files in
general - looks like this:

<?php
if (isset($_REQUEST['file_id'])) {
$file = new File($con, $_REQUEST['file_id']);
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Expires: 0");
header("Content-Type: " . $file->getMime());
header("Content-Length: " . $file->getSize());
header("Content-Disposition: attachment; filename=\"" . $file-
>getName()."\"");
header("Content-Transfer-Encoding: binary");
echo $file->getBlob();
exit;
}
echo "File not found!";
?>

As you can see I use a homebrew File class to contain the database
information, but that's not needed.

BE AWARE that IE relies heavily on the order of the headers, so use
the order I've used, and all will be fine :)

On Jun 7, 9:58 am, George Georgovassilis <g.georgovassi...@gmail.com>
wrote:


> While this has nothing to do with GWT, here is a link [1] to an
> example of a servlet that can stream images from a file - the file is
> the byte[] source and it's then written to the request. You'd probably
> only change the source, that is get the byte[] from querying a
> database.
>

> [1]http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/Q...


>
> On Jun 7, 8:01 am, "Sunita Mittal" <sunita.mit...@daffodildb.com>
> wrote:
>
>
>
> > Hello,
>
> > Currently the way we can make image is using the url and loading the
> > image from defined url.
>
> > But suppose , if I have a image stored in database and want to send the
> > byte[] to client and show the image by making a temp file at client side.
> > How it can be achived.
>
> > Or any other way We can manage showing image stored in database (i.e.
> > binary or BLOB data).
>
> > Thanks

> > Sunita Mittal.- Hide quoted text -
>
> - Show quoted text -

mP

unread,
Jun 7, 2007, 6:56:57 AM6/7/07
to Google Web Toolkit
It is not possible to create an image on the client from an array of
bytes. Most browsers ( pretty much all except IE ) can create an image
from a String. THe string must be a url that includes the a "data:"
protocol followed by the image base64 encoded. You could source this
String from a RPC. Your RPC could return a bunch of objects that
includes the base64 encoded String as a property. For IE rather than
the base64 image you would need a url which includes an identifier
back to the server which would then feed the image.

ANother possibility is to send back the base64 image to *all* browsers
including IE. For iE your browser would make a request back to the
server with the base64 data in the url. The server would decode the
base64 data and send it back to IE which would show your image as
normal. Its a bit silly as the data gets downlaoded twice and uploaded
once.

hth


On Jun 7, 3:01 pm, "Sunita Mittal" <sunita.mit...@daffodildb.com>
wrote:

Reply all
Reply to author
Forward
0 new messages