commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davis Ford <>
Subject Re: FileCleanerCleanup question
Date Tue, 20 Oct 2009 17:22:47 GMT
Hi, is anyone on this list familiar with commons-io / commons-fileupload?

If not, is there somewhere else I should be asking questions?

I still have the issue indicated below, and I have an additional question.

When you parse the request... =>

final List<FileItem> items = (List<FileItem>) upload.parseRequest(request);

commons-fileupload also generates files for form field items (e.g. text box
values).  This is an undesired side effect.  I want it to generate a file
for the actual file that is uploaded, but not the form fields.  Is there a
way to control that?

Thanks in advance,

On Mon, Oct 19, 2009 at 12:06 PM, Davis Ford

> Hi, it is my understanding from the commons-io javadoc, that if you create
> a FileCleanerCleanup it will remove files in a directory once the reference
> to the File is GC'd.
> Given that, I'm using commons-fileupload, and I set the listener in web.xml
> as:
> <listener>
> <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class>
> </listener>
> In my servlet, I have this:
> private static FileCleaningTracker tracker;
>     @Override
>     protected void initServletContext(ServletContext servletContext) {
>         super.initServletContext(servletContext);
>         tracker =
> FileCleanerCleanup.getFileCleaningTracker(servletContext);
>     }
> ...and in my method that accepts a file upload, I add the
> FileCleanerCleanup:
> final DiskFileItemFactory factory = new DiskFileItemFactory(0, tempDir);
> factory.setFileCleaningTracker(tracker);
> final ServletFileUpload upload = new ServletFileUpload(factory);
> My files are uploaded and stored in the temp directory as expected.  In the
> processing of a file upload, I store the FileItem object in the session as
> an attribute.  Now, if the session expires, I expect the attribute to be
> GC'd and as a result, the FileCleanerCleanup would go and cleanup the
> directory, but it does not.
> Can anyone tell me what I may be doing wrong?
> Thanks in advance,
> Davis

Zeno Consulting, Inc.
p: 248.894.4922
f: 313.884.2977

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