title: Upload a image in a porltet Liferay
body: <p>I am doing a portlet to create banners. I preferences I made the form with: <strong>input type="file"</strong> and the form <strong>nctype='multipart/form-data'</strong></p>
  
  <p>In the processAction I get the image, but I don't know how save it in the server, because I only get save in temporal instance portlet, but if I restart the server I lose the image.</p>
  
  <p>This is my code to save the image:</p>
  
  <pre><code>    private boolean uploadFile( ActionRequest request, ActionResponse response) throws ValidatorException, IOException, ReadOnlyException {
      try {
          // Si la request es del tipo multipart ...
          if (PortletFileUpload.isMultipartContent(request)) {
              DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
              PortletFileUpload servletFileUpload = new PortletFileUpload(diskFileItemFactory);
              servletFileUpload.setSizeMax(81920); // bytes
              List fileItemsList = servletFileUpload.parseRequest(request);
              Iterator it = fileItemsList.iterator();
  
          while (it.hasNext()){
              FileItem fileItem = (FileItem)it.next();
              if (fileItem.isFormField()){
              }
              else{
                  String nombreCampo = fileItem.getFieldName();
                  String nombreArchivo = fileItem.getName();
                  String extension = nombreArchivo.substring(nombreArchivo.indexOf("."));             
                  PortletContext context = request.getPortletSession().getPortletContext();
                  String path = context.getRealPath("/images");                   
                  File archivo = new File(path + "/" + nombreArchivo);
                  PortletContext pc = request.getPortletSession().getPortletContext();
                  fileItem.write(archivo);
              } 
          } 
      }
      } catch (Exception e) {}
      return true;
  }
  </code></pre>
  
  <p>I don't know if I am doing something wrong or this isn't the correct way.
  Any idea?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT:</strong>
  Finally I tried do it with DLFolderLocalServiceUtil and DLFileEntryLocalServiceUtil, but it doesn't work correctly. When I load the page you can see the image, but after, when the page is load completely, the image disappears. 
  I don't know if it is because I don't create fine the fileEntry or the url is wrong. 
  This is my code:</p>
  
  <pre><code>long folderId = CounterLocalServiceUtil.increment(DLFolder.class.getName());
  DLFolder folder = DLFolderLocalServiceUtil.createDLFolder(folderId);
  long userId = themeDisplay.getUserId();
  long groupId = themeDisplay.getScopeGroupId();
  folder.setUserId(userId);
  folder.setGroupId(groupId);
  folder.setName("Banner image " + nombreArchivo+String.valueOf(folderId));
  DLFolderLocalServiceUtil.updateDLFolder(folder);
  ServiceContext serviceContext= ServiceContextFactory.getInstance(DLFileEntry.class.getName(), request);
  File myfile =  new File(nombreArchivo);
  fileItem.write(myfile); 
  List&lt;DLFileEntryType&gt; tip = DLFileEntryTypeLocalServiceUtil.getFileEntryTypes(DLUtil.getGroupIds(themeDisplay));
  DLFileEntry DLfileEntry = DLFileEntryLocalServiceUtil.addFileEntry(userId, groupId, 0, folderId, null, MimeTypesUtil.getContentType(myfile), nombreArchivo, "Image banner_"+nombreArchivo, "", tip.get(0).getFileEntryTypeId(), null, myfile, fileItem.getInputStream(), myfile.getTotalSpace(), serviceContext);
  FileVersion fileVersion = null;
  //FileEntry fileEntry = DLAppServiceUtil.getFileEntry(groupId, folderId, nombreArchivo);
  //String path = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, "&amp;imagePreview=1");
  String path1 = themeDisplay.getPortalURL()+"/c/document_library/get_file?uuid="+DLfileEntry.getUuid()+"&amp;groupId="+themeDisplay.getScopeGroupId();
  String path = "/documents/" + DLfileEntry.getGroupId() + "/" + DLfileEntry.getFolderId() + "/" + DLfileEntry.getTitle()+"/"+DLfileEntry.getUuid();
  System.out.println("path " + path);
  System.out.println("path " + path1);
  prefs.setValue(nombreCampo, path);
  </code></pre>
  
  <p>And this is the output:</p>
  
  <pre><code>path /documents/10180/0/cinesa888.png/f24e6da2-0be8-47ad-a3b5-a4ab0d41d17f
  path http://localhost:8080/c/document_library/get_file?uuid=f24e6da2-0be8-47ad-a3b5-a4ab0d41d17f&amp;groupId=10180
  </code></pre>
  
  <p>I tried to get the url like lpratlong said (DLUtil) but when I tried to get the FileEntry with DLAppServiceUtil.getFileEntry(..) I have an error that says no exist FileEntry.</p>
  
  <p>I don't know what I am doing wrong.. Any idea?
  Thanks.</p>