Maybe it works right on Linux, but the temp file doesn't seem to get
deleted on Windows if there is actually data in it.  If an upload didn't
really happen, the 0-byte temp file is destrotyed.

There must still be a handle on it somehow:

/**
 * Saves an attachment to the TEMP_ATTACHMENTS table
 * @param aDiskFile The DiskFile object from the Struts framework
 * @param aAttachmentDesc The description of the file-attachment
 * @param aDatabase The database object
 * @param aStatement The statement object
 * @param aSession the HTTP session
 * @returns An empty string if successful or the error message for an
invalid file
 * @throws Exception A SQL or Logged exception
 */
public static String saveAttachment(final DiskFile aDiskFile,
                             final String aAttachmentDesc,
                             final DB aDatabase,
                             final Statement aStatement,
                             final HttpSession aSession) throws
Exception {
  Table_TEMP_ATTACHMENTS ta=new Table_TEMP_ATTACHMENTS();
  ta.init(aSession.getId());
  ta.setAttachmentName(aDiskFile.getFileName());
  ta.setMimeType(aDiskFile.getContentType());
  ta.setAttachmentDesc(aAttachmentDesc);
  ta.setBlob(aDiskFile);
  if (aDiskFile.getFileSize()>0) {
    ta.save(aDatabase,aStatement);
    aDiskFile.destroy(); // <---------------------------  Not working
    return StringEx.EMPTY_STRING;
  }
  else
    return "ERROR: The file '"+aDiskFile.getFileName()+"' does not exist
or is empty.";
}


From: SCHACHTER,MICHAEL (HP-NewJersey,ex2) <[EMAIL PROTECTED]>
Subject: FormFile.destroy() vs DiskFile.destroy() -- bug?
Date: Thu, 6 Sep 2001 09:50:09 -0700 
Content-Type: text/plain;
        charset="iso-8859-1"

Min,

Since FormFile is an interface, you're calling on DiskFile.destroy()
regardless.
However, DiskFile.destroy() calls on java.io.File.delete().  I've
encountered
problems in the past with java.io.File.delete() where the file doesn't
get
deleted.
I'll file a bug report on this and get to it when I have a chance.

-----Original Message-----
From: Mindaugas Idzelis [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 06, 2001 10:39 AM
To: struts
Subject: FormFile.destroy() vs DiskFile.destroy() -- bug?


Struts,

        It seems to me that there is a problem in either FormFile or
DiskFile. In
order for me to get the path information about the file stored on disk,
I
have to cast FormFile to DiskFile and call getFilePath(). It would be
convenient if DiskFile.destroy() would actually get rid of the temporary
files. In order for me to get rid of them I have to up-cast DiskFile to
FormFile and then call destroy() on the interface. As far as I can tell,
calling destroy() on DiskFile does nothing. Is this a bug or a feature?

--Min Idzelis


Reply via email to