You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2005/05/31 18:39:46 UTC

[Myfaces Wiki] Update of "Setup For File Uploads" by Brandon Goodin

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by Brandon Goodin:
http://wiki.apache.org/myfaces/Setup_For_File_Uploads

New page:
== Setup For File Uploads ==


'''1)''' Make sure you have configured the extension filter in the web.xml

{{{
<!-- Extensions Filter -->
    <filter>
        <filter-name>extensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>uploadMaxFileSize</param-name>
            <param-value>100m</param-value>
            <description>Set the size limit for uploaded files.
                Format: 10 - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g - 1 GB
            </description>
        </init-param>
        <init-param>
            <param-name>uploadThresholdSize</param-name>
            <param-value>100k</param-value>
            <description>Set the threshold size - files
                    below this limit are stored in memory, files above
                    this limit are stored on disk.

                Format: 10 - 10 bytes
                        10k - 10 KB
                        10m - 10 MB
                        1g - 1 GB
            </description>
        </init-param>
	<!--
	<init-param>
            <param-name>uploadRepositoryPath</param-name>
            <param-value>/temp</param-value>
            <description>Set the path where the intermediary files will be stored.
            </description>
        </init-param>
	-->
    </filter>

    <filter-mapping>
        <filter-name>extensionsFilter</filter-name>
        <url-pattern>*.shtml</url-pattern>
    </filter-mapping>
}}}
 
   
'''2)''' Make sure your form is properly encoded and add the x:inputFileUpload

{{{
<h:form enctype="multipart/form-data" id="myForm" name="myForm">
...
<x:inputFileUpload 
  id="category_image_upload" 
  storage="file" accept="image/*" 
  styleClass="myStyle" 
  value="#{myBackingBean.myUploadedFile}"/>
...
</h:form>
}}}


'''3)''' add !UploadedFile instance variable and setter/getter to backing bean

{{{
public class MyBackingBean {
...
  private UploadedFile myUploadedFile;
...
  public UploadedFile getMyUploadedFile() {
    return myUploadedFile;
  }

  public void setMyUploadedFile(UploadedFile myUploadedFile) {
    this.myUploadedFile = myUploadedFile;
  }
...
}
}}}


'''4)''' Add code to a form action method that retrievest the contents of !UploadedFile for handling

{{{
public class MyBackingBean {
  ...
  public String myAction () {
    ...
    ... myUploadedFile.getBytes();
    ... myUploadedFile.getContentType();
    ... myUploadedFile.getName();
    ...
    return "success";
  }
  ...
}
}}}