File uploading in to document and library portlet:

In this example i have done with liferay 6.06 version working fine.

In upload.jsp:

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:actionURL name="uploadBook" var="upload"></portlet:actionURL>
<form action="<%=upload.toString()%>" method="post" enctype="multipart/form-data">
 <input type="file" name="file"/ name='<portlet:namespace/>file'>
 <input type="submit" value="Upload Book" />
</form>
in controller class:
  public void uploadBook(ActionRequest actionRequest,
                            ActionResponse actionRresponse) throws PortletException,
                            IOException, com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException {
           UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
               String submissionFileName = uploadRequest.getFileName("file");//uploaded filename
           ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
               ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
              int i=0;
               File file3 = uploadRequest.getFile("file");
                long userId=10169;
              long groupId=10157;
              long folderId=11502;
              java.lang.String name=submissionFileName;
              java.lang.String title=submissionFileName;
              java.lang.String description=submissionFileName+"related to computerscience";
              java.lang.String changeLog="";
              java.lang.String extraSettings=""
              System.out.println("user id:"+userId);
                   System.out.println("group id"+groupId);
                   System.out.println("folder id"+folderId);
                   System.out.println("file name"+name);
                   System.out.println("title"+title);
                   System.out.println("description"+description);
                   System.out.println("changelog"+changeLog);
                   System.out.println("extraSettings"+extraSettings);
                   System.out.println("file location"+file3);
                   System.out.println(serviceContext);
                   System.out.println();
    DLFileEntryLocalServiceUtil.addFileEntry(  
  userId,                                                          groupId,                                                          folderId,
  name,
  title,                                                            description,                                                      changeLog,                                                        extraSettings,
  file3,                                                            serviceContext);
             
           String successMessage ="File Uploaded Successfully";
         SessionMessages.add(actionRequest, "request_rocessed",successMessage);
         i++;
        

    }

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.