commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <>
Subject Re: commons.fileupload: only memory usage
Date Thu, 25 Jun 2009 15:40:54 GMT
2009/6/22 Jantek Bal√°zs <>

> Hi!
> I would like to ask if it is possible to configure
> a fileItemFactory so that it never uses the file system.
> I would need a kind of MemoryFileItemFactory.. :-)

That's probably your best bet, if you really want to *never* use the file
system. That is, write a MemoryFileItemFactory and configure FileUpload to
use that.

> My problem is that my webapp has no access to the file system.
> If i set a large threshold on a DefaultFileItemFactory of
> a DiskFileItemFactory, i always get permission exceptions.

I don't know why you would be getting permission exceptions if your files
are always below the size threshold you set. The only possibility I see is
that the servlet container is causing this, in which case I'm not sure
there's anything you would be able to do about it. You'd have to debug /
look at the stack trace to find out where the exception is coming from.

I also don't know why you are setting a repository if you don't ever expect
your uploads to be written to file. If you set the size threshold suitably
high and don't set a repository, you shouldn't have any problems (modulo the
container itself, as mentioned above).

Martin Cooper

> I would like to separate the uploaded small (xml) files so
> that my servlet doesn't hit the file system.
> Do you have any ideas?
> Thanks!
> jb
> **********
> DiskFileItemFactory factory = new DiskFileItemFactory();
>                        // Set factory constraints
>                        factory.setSizeThreshold(1024 * 1024);
>                        factory.setRepository(new File("tempfile.tmp"));
>                        // Create a new file upload handler
>                        ServletFileUpload upload = new
> ServletFileUpload(factory);
>                        try {
>                                List items = upload.parseRequest(request);
>                                // PERMISSION EXCEPTION HERE
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

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