Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

image upload/download with mysql (jsp/servlet)

Thread view: 
KevinRobinson - 15 Nov 2005 18:33 GMT
Hi,

Can anyone please supply me with a coding solution to uploading /
downloading images to a mysql database.Or can anyone recommend

a book containing a solution for this problem.

I realise that images can be stored as blobs and also realise that the path
to the image if stored on the server can also be stored in the DB.

Not sure which is the best solution for this.

Any advice would be appreciated.

Thanks

Kevin
Roedy Green - 15 Nov 2005 18:57 GMT
On Tue, 15 Nov 2005 18:33:29 +0000 (UTC), "KevinRobinson"
<k.s.robinson@btinternet.com> wrote, quoted or indirectly quoted
someone who said :

>Can anyone please supply me with a coding solution to uploading /
>downloading images to a mysql database.Or can anyone recommend

Where is your image to start?  Let's say in a flat file on disk.  Just
load it in one fell swoop into a byte[].  See
http://mindprod.com/applets/fileio.html
for the code.

Now you can feed it as a BLOB to your database.

Now you fetch it back as a blob and turn in back into a byte[].

Now you want to render it.  You could convert your byte[] to a
byteArrayInputStream.  again see the file i/o amanuensis for how.
Then use ImageIO to read the bytes to create a image. See
http://mindprod.com/jgloss/imageio.html
BufferedImage image = ImageIO.read ( new ByteArrayInputStream (
rawImageBytes ) );

Alternatively you could use:

Toolkit.getDefaultToolkit().createImage( rawByteArray , start, length
);
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.