You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Ward, James" <Ji...@us.army.mil> on 2003/03/19 15:45:00 UTC

FileUpload - delete

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

RE: FileUpload - delete

Posted by Schalk <sc...@volume4.co.za>.
James