On 10/15/06, Mikkel Jensen <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to