commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <mart...@apache.org>
Subject Re: [fileupload] Having only files saved to disk?
Date Sun, 15 Oct 2006 17:59:06 GMT
On 10/15/06, Mikkel Jensen <mikkel_j@stofanet.dk> wrote:
>
> Hi everyone,
>
> Is it possible to have only uploaded files and NOT form fields saved to
> disk (no matter the size)?
>
> On DiskFileItemFactory I can set the sizeThreshold attribute to zero but
> this has the unwanted sideeffect of also caching plain form fields! Can this
> be avoided somehow or will I have to hack the source?


You won't need to hack the source, since FileUpload's customisation scheme
allows for this kind of thing. There are two ways you could tackle this;
which one you choose will depend on the exact behaviour you want to achieve.

1) Create your own FileItemFactory implementation that looks a whole lot
like DiskFileItemFactory, but which looks at the value of 'isFormField' and
overrides the value of 'sizeThreshold' that is actually passed to the
DiskFileItem constructor. For example, if it's a form field, set the
threshold high, so that it won't be written to disk, and if it's not a form
field, leave the value alone, to honour the original setting.

2) Subclass DiskFileItem and override getOutputStream to return an
appropriate kind of output stream, based on the value of 'isFormField'.
Depending on the kinds of output streams you use, you may need to modify
other methods in the class to handle the differences. Of course, you'll also
need to implement your own factory class to create this new FileItem
subclass.

If the first method gives you sufrficient control (which it seems like it
will), that would definitely be the simpler way to go.

--
Martin Cooper


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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message