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 / Databases / April 2004

Tip: Looking for answers? Try searching our database.

Upload Blob to database

Thread view: 
Peter Kirk - 04 Mar 2004 09:02 GMT
Hi, I am working on part of an application which has to upload an image from
a webpage and insert it as a blob in a database.

Yes, I would rather just store the image on the filesystem, and have a "file
path" or something in the database, but I have to store the image blob in
the database.

I am still looking at how to do this, so pointers would be appreciated. So
far my plan is:

(1) upload file to a temporary directory on file system;
(2) insert image (+ other data) into the database (I still have to find out
how to do the blob insert);
(3) delete file and temporary directory;

Is there a better way - can I directly take the image out of the request and
insert into the database, or do I need to write it the file system first?

Thanks for any pointers,
Peter
Mike Hoover - 05 Mar 2004 10:10 GMT
I am trying to do something similar so I'd be interested in hearing some
advice on this. I am new to Java and JSP and was reading a book about this.
It said Tomcat can't do multi-part html forms, so I think I will have to use
php or something.

Mike

> Hi, I am working on part of an application which has to upload an image from
> a webpage and insert it as a blob in a database.
[quoted text clipped - 16 lines]
> Thanks for any pointers,
> Peter
Peter Kirk - 05 Mar 2004 12:29 GMT
> I am trying to do something similar so I'd be interested in hearing some
> advice on this. I am new to Java and JSP and was reading a book about this.
> It said Tomcat can't do multi-part html forms, so I think I will have to use
> php or something.

Hi there, as far as I know Tomcat has no trouble with multipart forms, but
I'm no expert in this area...

But I have gone with the mechanism I proposed in my original post (it is
running on Resin, but I really don't see why this should affect the
results). It has been somewhat complicated by Oracle blobs (I think there is
something odd about their jdbc driver - but again, I am new to blobs, so it
could just be me with incorrect preconceptions).

Anyway, I use "commons-fileupload" to upload the image, then I write it to
the file system as a "temporary file", and do some funny gymnastics
streaming the file data to the oracle blob in the database.

Seems to work. I think it might be possible to avoid the step of writing the
file to the file system, as commons-fileupload provides an InputStream with
the data, but I haven't investigated that yet.

FYI, my HTML form looks like this:

<form action="/proj/servlet/Uploadservlet" method="post" name="uploadform"
enctype="multipart/form-data">
 <input type="hidden" name="UPLOAD_ID" value="<%=(String)data.get("ID")%>">
 <input type="hidden" name="UPLOAD_TYPE" value="PICTURE">
 <input type="file" name="uploadfile">
 <input type="submit">
</form>

This uploads the image file to my "Uploadservlet", which then handles
processing the data (with commons-fileupload), updating the database etc.
The UPLOAD_ID identifies the row in the database I am updating; and
UPLOAD_TYPE is used because other parts of the application also use this
servlet, and I have to identify myself as a "picture" upload.

Peter
Hiran Chaudhuri - 05 Mar 2004 12:46 GMT
> I am trying to do something similar so I'd be interested in hearing some
> advice on this. I am new to Java and JSP and was reading a book about this.
[quoted text clipped - 11 lines]
> > path" or something in the database, but I have to store the image blob in
> > the database.

I have built something like this with Resin, Apache Jakarta Commons
FileUpload and Software AG's Tamino.
No problems to upload files up to 15 MB, and even bigger as soon as we
modified some database parameters.

Hiran
Yan Lijun - 16 Apr 2004 08:26 GMT
i also have a problem about this,maybe it seems stupid.
i also have a problem about this maybe it seems stupid.

i create an instance of PreparedStatment from a connection with a sql
command,but how can i create an object which implements java.sql.Blob,and the
question is where is class implementing the interface java.sql.Blob.i can not
found anything in the package java.sql.Is it depended on a specific driver
class?

Thanks.
gumpagain@163.com
/**
/* Java Is Not Platform-independent.It Is The Platform!
*/
Igor N. Kolomiyets - 16 Apr 2004 10:52 GMT
There are two ways of dealing with this.

First, use the database dependent techniques to create and submit a blob
object into it. Almost all JDBC driver vendors provide such.

Second one, you first create an empty BLOB by the SQL means. Then do select
blob from .... for update and modify its content. Both statements should be
executed in the one transaction. This method works only if the database
you're intended to use provides with the built-in function that creates an
empty BLOB.

Best regards,
Igor.

> i also have a problem about this,maybe it seems stupid.
> i also have a problem about this maybe it seems stupid.
[quoted text clipped - 10 lines]
> /* Java Is Not Platform-independent.It Is The Platform!
> */


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.