Class UploadedFile

java.lang.Object
net.sf.basedb.clients.web.fileupload.UploadedFile

public class UploadedFile
extends Object
Objects of this class can be used to get information about an uploaded file and save the file to a directory in the filesystem. If the file is not saved, it will be deleted once the object is garbage collected.
Version:
2.0
Author:
Nicklas
  • Field Details

    • fu

      private FileUpload fu
    • formName

      private final String formName
    • filename

      private final String filename
    • mimeType

      private final String mimeType
  • Constructor Details

    • UploadedFile

      UploadedFile​(FileUpload fu, String formName, String filename, String mimeType)
      Create a new UploadedFile object. Use the FileUpload.getFile(String) or FileUpload.getFileValues(String) method to get an object representing the uploaded file.
      Parameters:
      fu - The FileUpload object responsible for the upload
      formName - The name of the form field with this file
      mimeType - The MIME type of the file, or NULL if it is not known
      filename - The original filename of the file, or NULL if it is not known
  • Method Details

    • getFormName

      public String getFormName()
      Get the name of the form field that this file was selected in.
      Since:
      2.16
    • getFilename

      public String getFilename()
      Get the original filename of the uploaded file. This is the name the file had on the client computer.
      Returns:
      The original name of the file, or NULL if it is not known
    • getExtension

      public String getExtension()
      Get the extension of the original filename. The extension is the part of the filename after the last dot. If the file doesn't have an extension NULL is returned.
      Returns:
      The extension of the file, or NULL if none exists
    • getMimeType

      public String getMimeType()
      Get the MIME type of the uploaded file.
      Returns:
      The MIME type of the file, or NULL if it is not known
    • writeTo

      public void writeTo​(OutputStream out) throws IOException, UploadAbortedException
      Upload the file and write the data to the specified output stream.
      Parameters:
      out - The stream to write to
      Throws:
      IOException
      UploadAbortedException
    • getInputStream

      public InputStream getInputStream() throws IOException, UploadAbortedException
      Get an input stream for uploading the file.
      Returns:
      An input stream to read from
      Throws:
      IOException - If reading the input stream fails.
      UploadAbortedException - If the upload has been requested to be aborted.