title: Attaching file in a web form portlet
body: <p>I am trying to add a field in web form portlet of liferay to upload a file. Currently I am able to add this field in my form but unable to get the attached file on server/ mentioned location. I am getting a null pointer exception. Below are the changes I have done in 4 files of web form portlet.</p>
  
  <h1>edit_field.jsp</h1>
  
  <pre><code>   &lt;aui:option selected='&lt;%= fieldType.equals("file") %&gt;' value="file"&gt;
     &lt;liferay-ui:message key="file" /&gt;&lt;/aui:option&gt;
  </code></pre>
  
  <h1>view.jsp</h1>
  
  <pre><code> &lt;c:when test='&lt;%= fieldType.equals("file") %&gt;'&gt;
       &lt;tr&gt;
        &lt;td class="order-table-label"&gt;
          &lt;label&gt;&lt;%= HtmlUtil.escape(fieldLabel) %&gt;&lt;/label&gt;
       &lt;/td&gt;
       &lt;td&gt;
       &lt;aui:input cssClass='&lt;%= fieldOptional ? "optional" : StringPool.BLANK 
      %&gt;' label="" name="&lt;%= fieldName %&gt;" type="file" value="
      &lt;%=HtmlUtil.escape(fieldValue) %&gt;"/&gt;
      &lt;/td&gt;
     &lt;/tr&gt;
   &lt;/c:when&gt;
  </code></pre>
  
  <h1>ConfigurationActionImpl.java</h1>
  
  <pre><code>  boolean isFileUpload = false;
  
    if("file".equals(fieldType))
    {
     isFileUpload = true;
     }
    preferences.setValue("isFileUpload" + i, String.valueOf(isFileUpload));
  </code></pre>
  
  <p>WebFormPortlet.java</p>
  
  <pre><code>  UploadPortletRequest uploadRequest = 
    Portalutil.getUploadPortletRequest(actionRequest);
  
    File uploadedFile = uploadRequest.getFile("file");
  
    String sourcefileName = uploadRequest.getFileName(uploadedFile.getName());
    (Throws NULL pointer exception on this line)
  
    File folder = new File("\tmp\uploadedfile");
  
    File filepath = new File(folder.getAbsolutePath() + File.seperator + 
    sourcefileName);
  
    FileUtils.copyFile(uploadedFile ,filepath);
  </code></pre>