List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:January 13 2003 6:58pm
Subject:Re: Embedding images stored in database
View as plain text  
In the last episode (Jan 13), Toomas said:
> Hello List,
> 
> Is there a simplier way to embed an image stored in BLOB field into
> HTML than using 2 calls to Perl scripts - one to generate HTML and
> another call from that HTML via IMG tag to retrieve and print image?
> I mean, something like you do it in a multipart e-mail message?

You can actually do this with HTML as well, by using the little-used
"data:" URI.  Try copying this into a file and loading it up in a
broswer:

<h1>Demonstration of embedding GIF image directly in document</h1>
This is embedded image: <img
src="data:image/gif;base64,R0lGODlhDwAPAJEBAAAAAL+/v///
AAAAACH5BAEAAAEALAAAAAAPAA8AAAIujA2Zx5EC4WIgWnnq
vQBJLTyhE4khaG5Wqn4tp4ErFnMY+Sll9naUfGpkFL5DAQA7" />

It's not all that efficient, though, since the image is sent in base-64
and the server sends it on every page load (instead of letting the
browser fetch it once and then cache it).

If you're worried about the impact of launching a CGI every time you
need to pull an image out of the database, see if your webserver has an
SQL filesystem module, or something that will let you pull data
straight out of the database without involving scripts at all.

-- 
	Dan Nelson
	dnelson@stripped
Thread
Embedding images stored in databaseToomas13 Jan
  • Re: Embedding images stored in databaseDan Nelson13 Jan