Avatar billede fredand Forsker
05. november 2003 - 12:55 Der er 1 kommentar og
1 løsning

Show image stored in a database

Hello!

Supose that you have a image in a BLOB in a database, do not ask me why you ever would have it like that. Just supose that.

Then supose that you should show that image in a HTML-document, like:
<HTML>
<HEAD>
</HEAD>
<BODY>
  <H3>The image</H3>
  <IMAGE????>
</BODY>
</HTML>

Is there a smarter way then this psudeocode:
1)Retrive the image from the database
2)Store it like a file
3)Create the HTML-output with <IMAGE SRC="images/theimg.gif">
4) Return the the HTML-output to the client.

Is there a smarter way then this approach when you have the image in the database like a BLOB? Is it possible to do it differently with some other technich?

Best regrads
Fredrik
Avatar billede arne_v Ekspert
05. november 2003 - 12:59 #1
It is quite common to store files in databases.

Yes - there are a smarter way.

Let the JSP page generate links as:

<IMG SRC="/GetPictureServlet?image=xxxx">

And create the GetPictureServlet that:
  - gets the BLOB
  - sets the correct Content-Type (very important !!!!)
  - output the bytes
Avatar billede fredand Forsker
05. november 2003 - 14:34 #2
Hello!

Ok, I see.

Thanks mate!

Best regards
Fredrik
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester