commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ward, James" <Jim.Wa...@us.army.mil>
Subject FileUpload - delete
Date Wed, 19 Mar 2003 14:45:00 GMT
I have a basic FileUpload working, using JAVA 1.4.1_01 with tomcat
4.1.18, on Windows 2000.  The problem is I can't seem to get rid of the
tmp files created.  They stay there and everytime I upload a file in the
appliction, another set are created, making the number and total size
and number of tmp files ever larger.  I've tried putting delete in, to
no avail.  Usually when I shut down the server and restart it, they are
cleared out, but not always, which seems strange.  Thanks if advance for
any help.  Here is the code:

FileUpload fu = new FileUpload();
fu.setSizeMax(1000000);

// maximum size that will be stored in memory
fu.setSizeThreshold(4096);

// the location for saving data that is larger than getSizeThreshold()
fu.setRepositoryPath("d:/temp");
List fileItems = null;

try {
   fileItems = fu.parseRequest(req);
}
catch (FileUploadException e) {
   getServletContext().log("Could not parseRequest ",e);
   res.sendError(res.SC_INTERNAL_SERVER_ERROR,"Could not parseRequest
");
}

DefaultFileItem fi = null;
Iterator i = fileItems.iterator();

while (i.hasNext() ) {
   fi = (DefaultFileItem)i.next();
   if (fi.isFormField()) {
      fields.put(fi.getFieldName(),fi.getString());
      if ("proposal_number".equals(fi.getFieldName())) {
         proposalNumber = (String)fields.get("proposal_number");
      }
   }
   else {
      fileName = fi.getName();
      if (fileName == null || fileName.length() <= 0) {
         continue;
      }
      fi.getInputStream();
      newFileName = proposalNumber.trim() + "_ipr" +
      fileName.substring(fileName.lastIndexOf("."),
      fileName.length());
      try {
         fi.write("d:/temp/" + newFileName);
      }
      catch (Exception e) {
         getServletContext().log("Could not write file ",e);
         res.sendError(res.SC_INTERNAL_SERVER_ERROR,"Could not write
file ");
      }
   }
   fi.delete();
}

Jim Ward
CISD-RTP Contractor
Army Research Office

Mime
View raw message