apex:inputFile

A component that creates an input field to upload a file.

Note: The maximum file size that can be uploaded via Visualforce is 10 MB.

Example 

1<!-- Upload a file and put it in your personal documents folder-->
2
3<!-- Page: -->
4<apex:page standardController="Document" extensions="documentExt">
5    <apex:messages />
6    <apex:form id="theForm">
7      <apex:pageBlock>
8          <apex:pageBlockSection>
9            <apex:inputFile value="{!document.body}" filename="{!document.name}"/>
10            <apex:commandButton value="Save" action="{!save}"/>
11          </apex:pageBlockSection>
12       </apex:pageBlock>
13    </apex:form>
14</apex:page>
15                
16/*** Controller ***/
17public class documentExt {
18    public documentExt(ApexPages.StandardController controller) {
19        Document d = (Document) controller.getRecord();
20        d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents
21    }                 
22}

Attributes 

Attribute NameAttribute TypeDescriptionRequired?API VersionAccess
acceptStringComma-delimited set of content types. This list can be used by the browser to limit the set of file options that is made available for selection. If not specified, no content type list will be sent and all file types will be accessible. 14.0
accessKeyStringThe keyboard access key that puts the component in focus. 14.0
altStringAn alternate text description of the component. 14.0
contentTypeStringString property that stores the uploaded file’s content type. 14.0
dirStringThe direction in which the generated HTML component should be read. Possible values include “RTL” (right to left) or “LTR” (left to right). 14.0
disabledBooleanA Boolean value that specifies whether this component should be displayed in a disabled state. If set to true, the component appears disabled. If not specified, this value defaults to false. 14.0
fileNameStringString property that stores the uploaded file’s name. 14.0
fileSizeIntegerInteger property that stores the uploaded file’s size. 14.0
idStringAn identifier that allows the component to be referenced by other components in the page. 14.0global
langStringThe base language for the generated HTML output, for example, “en” or “en-US”. For more information, see the W3C specification on this attribute: http://www.w3.org/TR/REC-html40/struct/dirlang.html 14.0
onblurStringThe JavaScript invoked if the onblur event occurs–that is, if the focus moves off of the component. 14.0
onchangeStringThe JavaScript invoked if the onchange event occurs–that is, if the user changes the content of the component field. 14.0
onclickStringThe JavaScript invoked if the onclick event occurs–that is, if the user clicks the component. 14.0
ondblclickStringThe JavaScript invoked if the ondblclick event occurs–that is, if the user clicks the component twice. 14.0
onfocusStringThe JavaScript invoked if the onfocus event occurs–that is, if the focus is on the component. 14.0
onkeydownStringThe JavaScript invoked if the onkeydown event occurs–that is, if the user presses a keyboard key. 14.0
onkeypressStringThe JavaScript invoked if the onkeypress event occurs–that is, if the user presses or holds down a keyboard key. 14.0
onkeyupStringThe JavaScript invoked if the onkeyup event occurs–that is, if the user releases a keyboard key. 14.0
onmousedownStringThe JavaScript invoked if the onmousedown event occurs–that is, if the user clicks a mouse button. 14.0
onmousemoveStringThe JavaScript invoked if the onmousemove event occurs–that is, if the user moves the mouse pointer. 14.0
onmouseoutStringThe JavaScript invoked if the onmouseout event occurs–that is, if the user moves the mouse pointer away from the component. 14.0
onmouseoverStringThe JavaScript invoked if the onmouseover event occurs–that is, if the user moves the mouse pointer over the component. 14.0
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. 14.0global
requiredBooleanA Boolean value that specifies whether this component is a required field. If set to true, the user must specify a value for this component. If not selected, this value defaults to false. 14.0
sizeIntegerSize of the file selection box to be displayed. 14.0
styleStringThe style used to display the component, used primarily for adding inline CSS styles. 14.0
styleclassStringThe style class used to display the component, used primarily to designate which CSS styles are applied when using an external CSS stylesheet. 14.0
tabindexIntegerThe order in which this component is selected compared to other page components when a user presses the Tab key repeatedly. This value must be an integer between 0 and 32767, with component 0 being the first component that is selected when a user presses the Tab key. 14.0
titleStringThe text displayed next to the component when the mouse hovers over it. 14.0
valueBlobA merge field that references the controller class variable that is associated with this component. For example, if the name of the associated variable in the controller class is myInputFile, use value="{!myInputFile}" to reference the variable.Yes14.0

See Also