You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ralf Hauser <ra...@gmx.ch> on 2003/10/03 07:01:56 UTC

how to read uploaded FormFile InputStream multiple times?

Hi,

we use the <html:file to upload also large attachments into a web-mail
application.
First we put it into the database, but immediately thereafter, we would like
to send it off to multiple recipients via encrypted mail.

We get a "Bad File Descriptor" when trying to access the data for a second
time after putting it into the database.
doing a inputStream.reset() gives a "java.io.IOException: mark/reset not
supported".
If we wipe the attachment from the session and get it from the (MySQL)
database again, reset() works beautifully and we can read it many times. But
going back and forth to the database is a big waste if the InputStreams get
large.

Therefore my request to enhance the documentation in
http://jakarta.apache.org/struts/api/org/apache/struts/upload/FormFile.html#
getInputStream(): how can one use such an InputStream multiple times?

Many thanks for any hints!

	Ralf (ralfhauser@gmx.ch)

P.S.: We figured that Blobs coming from MySQL are actually
ByteArrayInputStream thus having a reset() implemented. However, as we tried
to convert data coming from struts FormFile to ByteArrayInputStream
ourselves, it got corrupted.


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


Re: how to read uploaded FormFile InputStream multiple times?

Posted by Vikram Goyal <v....@uq.edu.au>.
You are better off using FileUpload from the Commons package. Using
DiskFileUpload, you can set a threshold on the size of your files. If the
threshold is breached, the files will be saved in a temp location on your
hard disk from where you can access them as many times as you want. So you
could first save them to the database and then do whatever else you want.
You could even enhance the FileUploadBase to do exactly as you want, i.e,
write to the database and then still give you a handle on a perhaps new
input stream.

--
Vikram


----- Original Message ----- 
From: "Craig R. McClanahan" <cr...@apache.org>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, October 03, 2003 3:11 PM
Subject: Re: how to read uploaded FormFile InputStream multiple times?


> Ralf Hauser wrote:
>
> >Hi,
> >
> >we use the <html:file to upload also large attachments into a web-mail
> >application.
> >First we put it into the database, but immediately thereafter, we would
like
> >to send it off to multiple recipients via encrypted mail.
> >
> >We get a "Bad File Descriptor" when trying to access the data for a
second
> >time after putting it into the database.
> >doing a inputStream.reset() gives a "java.io.IOException: mark/reset not
> >supported".
> >If we wipe the attachment from the session and get it from the (MySQL)
> >database again, reset() works beautifully and we can read it many times.
But
> >going back and forth to the database is a big waste if the InputStreams
get
> >large.
> >
> >Therefore my request to enhance the documentation in
>
>http://jakarta.apache.org/struts/api/org/apache/struts/upload/FormFile.html
#
> >getInputStream(): how can one use such an InputStream multiple times?
> >
> >Many thanks for any hints!
> >
> >
> Your best bet is to assume that you cannot *ever* read the same input
> stream more than once.  There is no guarantee in the servlet spec that
> this is possible, and it would be prohibitively expensive for a
> container to make such a guarantee, so this is not really a Struts isse
> or even a commons-fileupload issue.  It's an unwarranted assumption that
> you are making -- and such assumptions are more likely than not to be
> non-portable.
>
> The only sane thing to do is to make sure that your *application* has
> stored the uploaded file data where your *application* can find it
> again.  Expecting reset() to work is pretty much guaranteed to cause
> your application to fail.
>
> Note the emphasis in the above paragraph -- this is primarily an
> application issue, not a framework issue or a container issue.
>
> > Ralf (ralfhauser@gmx.ch)
> >
> >
> Craig
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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


Re: how to read uploaded FormFile InputStream multiple times?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Ralf Hauser wrote:

>Hi,
>
>we use the <html:file to upload also large attachments into a web-mail
>application.
>First we put it into the database, but immediately thereafter, we would like
>to send it off to multiple recipients via encrypted mail.
>
>We get a "Bad File Descriptor" when trying to access the data for a second
>time after putting it into the database.
>doing a inputStream.reset() gives a "java.io.IOException: mark/reset not
>supported".
>If we wipe the attachment from the session and get it from the (MySQL)
>database again, reset() works beautifully and we can read it many times. But
>going back and forth to the database is a big waste if the InputStreams get
>large.
>
>Therefore my request to enhance the documentation in
>http://jakarta.apache.org/struts/api/org/apache/struts/upload/FormFile.html#
>getInputStream(): how can one use such an InputStream multiple times?
>
>Many thanks for any hints!
>  
>
Your best bet is to assume that you cannot *ever* read the same input 
stream more than once.  There is no guarantee in the servlet spec that 
this is possible, and it would be prohibitively expensive for a 
container to make such a guarantee, so this is not really a Struts isse 
or even a commons-fileupload issue.  It's an unwarranted assumption that 
you are making -- and such assumptions are more likely than not to be 
non-portable.

The only sane thing to do is to make sure that your *application* has 
stored the uploaded file data where your *application* can find it 
again.  Expecting reset() to work is pretty much guaranteed to cause 
your application to fail.

Note the emphasis in the above paragraph -- this is primarily an 
application issue, not a framework issue or a container issue.

>	Ralf (ralfhauser@gmx.ch)
>  
>
Craig



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