You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Jimmy Larsson <ji...@lecando.com> on 2001/02/14 09:51:30 UTC

File uploads (including "patches")

Hi all!

I think struts is a wonderful thing and I have been using it for the last
few weeks. I very pleased with it, except for the file uploading parts.

In our application we've been using file uploads via forms which we have
implemented our selves, but now we want to move to struts and then we need
the uploads working.

These are the issues I've found with the uploading:

1. If you upload a file with a content-type (extension) that the browser
does not know, the first "line" of the file gets truncated.

2. When decoding the multipart request the whole file is stored in memory
as an byte array. You cant have this since users uploding files can fill
up your memory.

3. When reading files in your action you can only read the files as a
bytearray in memory. You cant have this for the same reason as in 2, also
file-io in Java is intended to use streams.

----

I've attached sources for the upload package that fix these issues. 

Because I didn't want to break compability with things using the reading
of byte-arrays, I have not removed the "getFileData()" method from the
FormFile interface. I think this really should be done to prevent users
from using this dangerous method.

If it's ok with you guys I could put some more time into the code and
remove this method, there is also some cleaning up which I have not done.


/Regards, Jimmy Larsson

__________________________________________________________________________
Jimmy Larsson, Lecando AB, http://www.lecando.com                 
  e-mail: jimmy@lecando.com
  Tel: +46 (0)8 - 634 94 00, +46 (0)70 - 462 19 11

Re: File uploads (including "patches")

Posted by Wong Kok Wai <wo...@pacific.net.sg>.
With regard to point 2 and 3, a small suggestion: from JDK 1.2 onwards, you
can create temporary files. Maybe you can use this instead of managing the
temporary files.

Jimmy Larsson wrote:

>
> 2. When decoding the multipart request the whole file is stored in memory
> as an byte array. You cant have this since users uploding files can fill
> up your memory.
>
> 3. When reading files in your action you can only read the files as a
> bytearray in memory. You cant have this for the same reason as in 2, also
> file-io in Java is intended to use streams.
>