wicket.markup.html.form.upload
Class FileUpload

java.lang.Object
  extended by wicket.markup.html.form.upload.FileUpload
All Implemented Interfaces:
java.io.Serializable

public class FileUpload
extends java.lang.Object
implements java.io.Serializable

Model for file uploads.

Author:
Jonathan Locke
See Also:
Serialized Form

Method Summary
 void delete()
          Deletes temp file from disk
 byte[] getBytes()
           
 java.lang.String getClientFileName()
           
 java.lang.String getContentType()
           
 java.io.File getFile()
          Deprecated. - this method was very counterintuitive. its been replaced by getClientFileName(). see bug 1372481.
 java.io.InputStream getInputStream()
          Get an input stream for the file uploaded.
 long getSize()
           
 void writeTo(java.io.File file)
          Saves this file upload to a given file on the server side.
 java.io.File writeToTempFile()
          Convinience method that copies the input stream returned by getInputStream() into a temporary file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

delete

public void delete()
Deletes temp file from disk


getBytes

public byte[] getBytes()
Returns:
Uploaded file as an array of bytes

getContentType

public java.lang.String getContentType()
Returns:
Content type for upload

getFile

public java.io.File getFile()
Deprecated. - this method was very counterintuitive. its been replaced by getClientFileName(). see bug 1372481.

Returns:
File object for client-side file that was uploaded.

getClientFileName

public java.lang.String getClientFileName()
Returns:
name of uploaded client side file
Since:
1.2

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get an input stream for the file uploaded. Use this input stream if you can't use writeTo(File) for persisting the uploaded file. This can be if you need to react upon the content of the file or need to persist it elsewhere, i.e. a database or external filesystem.

PLEASE NOTE!
The InputStream return will be closed be Wicket at the end of the request. If you need it across a request you need to hold on to this FileUpload instead.

Returns:
Input stream with file contents.
Throws:
java.io.IOException

getSize

public long getSize()
Returns:
The upload's size

writeTo

public void writeTo(java.io.File file)
             throws java.io.IOException
Saves this file upload to a given file on the server side.

Parameters:
file - The file
Throws:
java.io.IOException

writeToTempFile

public final java.io.File writeToTempFile()
                                   throws java.io.IOException
Convinience method that copies the input stream returned by getInputStream() into a temporary file.

Only use this if you actually need a File to work with, in all other cases use getInputStream() or getBytes()

Returns:
temporary file containing the contents of the uploaded file
Throws:
java.io.IOException
Since:
1.2


Copyright © 2004-2007 Wicket developers. All Rights Reserved.