RE: Uploading files to a database

2004-08-20 Thread Jim Barrows


> -Original Message-
> From: Jim Barrows 
> Sent: Friday, August 20, 2004 1:14 PM
> To: Struts Users Mailing List
> Subject: RE: Uploading files to a database
> 
> 
> 
> 
> > -Original Message-
> > From: Ivan Vasquez [mailto:[EMAIL PROTECTED]
> > Sent: Friday, August 20, 2004 1:04 PM
> > To: [EMAIL PROTECTED]
> > Subject: Uploading files to a database
> > 
> > 
> > Hi,
> > 
> > What's the preferred way to upload files into a database in 
> a J2EE Web
> > application? 

Jakarta file-upload 
http://jakarta.apache.org/commons/fileupload/

> > 
> > Is there any way to stream the file straight from the 
> > HttpServletRequest
> > to the database without staging it in the server's filesystem? \

Answered the second quesiton, not the first...

> 
> Since you have to have the entire file before saving it into 
> the DB, you either store the entire file in memory, or put it 
> on the filesystem.
> I suppose you could, store the current buffer contents... 
> read the next buffer full, re-get the field, append the new 
> buffer to what's in the database, then update it.  course, 
> the only that does is beat the snot out of your database and 
> the GC, since you still have to have enough memory to store 
> the whole file in memory, plus bring it across the network 
> (filesize/buffersize)*2 times.  The GC of course would have 
> to run a lot as well, since you'd be dynamically allocating 
> 2(filesize/buffersize) buffers.  Your network traffic would 
> be something like 2(filesize/buffersize)buffersize.
> So u unless your db has that option, and a JDBC 
> connector that allowed it... no.
> 
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Uploading files to a database

2004-08-20 Thread Daniel Kalcevich
We use Struts to Upload files and store them as BLOB's in DB2.  We have
code similar to the following:

**FORM**

public void setufile(org.apache.struts.upload.FormFile uFile) {
   this.uFile = uFile;
}

private org.apache.struts.upload.FormFile getUFile () {
return uFile;
}


**ACTION**


UploadMessageForm upload = (UploadMessageForm)form;

..more code here for setting up insert...

pstmt = conn.prepareStatement( query );
pstmt.setBinaryStream(1, file.getInputStream()
,file.getInputStream().available() );
pstmt.execute();


The variable "file" is the value returned from upload.getUFile().

Hope this helps.

Daniel 


-Original Message-
From: Ivan Vasquez [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 20, 2004 1:04 PM
To: [EMAIL PROTECTED]
Subject: Uploading files to a database

Hi,

What's the preferred way to upload files into a database in a J2EE Web
application? 

Is there any way to stream the file straight from the HttpServletRequest
to the database without staging it in the server's filesystem? 

Thank you,
Ivan.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Uploading files to a database

2004-08-20 Thread Axel Seinsche
Ivan Vasquez schrieb:
Hi,
What's the preferred way to upload files into a database in a J2EE Web
application? 

Is there any way to stream the file straight from the HttpServletRequest
to the database without staging it in the server's filesystem? 

Thank you,
Ivan.
 

That's how I use it. But in my case I want to store a file on the 
server. But it should be easily possible to put the Stream to CLOB or 
something like this.

streamIn = file.getInputStream();
streamOut = new FileOutputStream(fileName);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
 streamOut.write(buffer, 0, bytesRead);
}
streamOut.close();
streamIn.close();
file.destroy();
file is a FormFile object which you can use with Struts with the 
 tag.

Cheers,
Axel
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Uploading files to a database

2004-08-20 Thread Erik Weber
I think Oracle Intermedia lets you create a BLOB directly from an 
InputStream.

But I prefer to keep my files on the file system and just put meta data 
about them in the database.

If you decide to write to the file system, the example file upload 
webapp that comes with Struts is nice. It uses jakarta commons file 
upload libraries behind the scenes, which are also nice.

Erik
Ivan Vasquez wrote:
Hi,
What's the preferred way to upload files into a database in a J2EE Web
application? 

Is there any way to stream the file straight from the HttpServletRequest
to the database without staging it in the server's filesystem? 

Thank you,
Ivan.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Uploading files to a database

2004-08-20 Thread Jim Barrows


> -Original Message-
> From: Ivan Vasquez [mailto:[EMAIL PROTECTED]
> Sent: Friday, August 20, 2004 1:04 PM
> To: [EMAIL PROTECTED]
> Subject: Uploading files to a database
> 
> 
> Hi,
> 
> What's the preferred way to upload files into a database in a J2EE Web
> application? 
> 
> Is there any way to stream the file straight from the 
> HttpServletRequest
> to the database without staging it in the server's filesystem? 

Since you have to have the entire file before saving it into the DB, you either store 
the entire file in memory, or put it on the filesystem.
I suppose you could, store the current buffer contents... read the next buffer full, 
re-get the field, append the new buffer to what's in the database, then update it.  
course, the only that does is beat the snot out of your database and the GC, since you 
still have to have enough memory to store the whole file in memory, plus bring it 
across the network (filesize/buffersize)*2 times.  The GC of course would have to run 
a lot as well, since you'd be dynamically allocating 2(filesize/buffersize) buffers.  
Your network traffic would be something like 2(filesize/buffersize)buffersize.
So u unless your db has that option, and a JDBC connector that allowed it... 
no.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Uploading files to a database

2004-08-20 Thread Ivan Vasquez
Hi,

What's the preferred way to upload files into a database in a J2EE Web
application? 

Is there any way to stream the file straight from the HttpServletRequest
to the database without staging it in the server's filesystem? 

Thank you,
Ivan.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]