From: ccc31807 on
If you have a table in a database with an ID field (int), name
(varchar), a content-type field (varchar) and a data field (blob), and
you have binary data in the data field (like GIFs, JPEGs, PDFs, etc.),
you can display these directly in a new HTML page. A query from the
the database returns this:
id => 666
name => greg.jpg
content-type => image/jpeg
data => &w`l *� m :��mF�΄�A�4d��

How would you embed this data in an HTML page with a Content-Type of
text/html? The <img> element needs a src attribute, which I don't
have, and the <object> element likewise needs a URI for the data
attribute.

I can certainly display the "data" from the database, but it's
character based data (clubs, diamonds, hearts, and spades) rather than
the nice, pretty picture that's really there. Is there a PM that can
take a binary and turn it into something that will look like an image
in a browser?

Thanks, CC.
From: Sherm Pendley on
ccc31807 <cartercc(a)gmail.com> writes:

> If you have a table in a database with an ID field (int), name
> (varchar), a content-type field (varchar) and a data field (blob), and
> you have binary data in the data field (like GIFs, JPEGs, PDFs, etc.),
> you can display these directly in a new HTML page. A query from the
> the database returns this:
> id => 666
> name => greg.jpg
> content-type => image/jpeg
> data => &w`l *� m :��mF�΄�A�4d��
>
> How would you embed this data in an HTML page with a Content-Type of
> text/html? The <img> element needs a src attribute

The src attribute can refer to a script, i.e. "src='image.pl?id=666'".
Then in image.pl, you'd fetch the image data and send it.

sherm--
From: Ben Morrow on

Quoth Sherm Pendley <spamtrap(a)shermpendley.com>:
> ccc31807 <cartercc(a)gmail.com> writes:
>
> > If you have a table in a database with an ID field (int), name
> > (varchar), a content-type field (varchar) and a data field (blob), and
> > you have binary data in the data field (like GIFs, JPEGs, PDFs, etc.),
> > you can display these directly in a new HTML page. A query from the
> > the database returns this:
> > id => 666
> > name => greg.jpg
> > content-type => image/jpeg
> > data => &w`l *� m :��mF�΄�A�4d��
> >
> > How would you embed this data in an HTML page with a Content-Type of
> > text/html? The <img> element needs a src attribute
>
> The src attribute can refer to a script, i.e. "src='image.pl?id=666'".
> Then in image.pl, you'd fetch the image data and send it.

This is the correct approach :). An alternative would be to construct a
data: url and supply that as the value of the src attribute. URI knows
how to correctly construct data: urls from arbitrary data; whether
browsers are willing to accept the very long urls necessary is another
matter entirely.

Ben