You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ivan Vasquez <iv...@itos.uga.edu> on 2004/08/20 22:03:40 UTC

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Uploading files to a database

Posted by Axel Seinsche <st...@seinsche.net>.
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 
<html:file > tag.

Cheers,
Axel

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Uploading files to a database

Posted by Erik Weber <er...@mindspring.com>.
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: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org