littlecowk35 / eic-quan-ly-cong-van

Automatically exported from code.google.com/p/eic-quan-ly-cong-van
0 stars 0 forks source link

How to process file in Liferay #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Idea: Using DLFileEntryService

Original issue reported on code.google.com by ntanh...@gmail.com on 19 Jul 2014 at 8:49

GoogleCodeExporter commented 9 years ago
https://www.liferay.com/documentation/liferay-portal/6.2/user-guide/-/ai/getting
-started-with-the-documents-and-media-portl-8

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 8:49

GoogleCodeExporter commented 9 years ago
https://www.liferay.com/community/forums/-/message_boards/message/7562469

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 8:50

GoogleCodeExporter commented 9 years ago
https://www.liferay.com/community/forums/-/message_boards/message/28289004

Original comment by ntanh...@gmail.com on 19 Jul 2014 at 8:54

GoogleCodeExporter commented 9 years ago
Create an example project follow these steps
https://www.liferay.com/community/forums/-/message_boards/message/14751142

Original comment by ntanh...@gmail.com on 21 Jul 2014 at 4:38

GoogleCodeExporter commented 9 years ago
Create view.jsp:
<aui:form action="<%= uploadURL.toString() %>" method="post" 
enctype="multipart/form-data">
    <aui:fieldset>
        <aui:fieldset > 
            <aui:input name="file" label="File" type="file" >
            </aui:input>
        </aui:fieldset>
    </aui:fieldset>
    <aui:fieldset >
        <aui:button-row> 
            <aui:button type="submit" value="Lưu" cssClass="btn-primary" ></aui:button>
        </aui:button-row>
    </aui:fieldset>
</aui:form>

Original comment by ntanh...@gmail.com on 21 Jul 2014 at 7:57

GoogleCodeExporter commented 9 years ago
Check out this post:
http://liferayway.blogspot.com/2013/09/uploading-file-example-in-liferay.html

Original comment by ntanh...@gmail.com on 21 Jul 2014 at 9:40

GoogleCodeExporter commented 9 years ago
How to create a DLFolder:
http://www.liferay.com/community/forums/-/message_boards/message/22391303

Original comment by ntanh...@gmail.com on 21 Jul 2014 at 9:41

GoogleCodeExporter commented 9 years ago
Code in the control part:
 ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        File file = uploadRequest.getFile("file");
        System.out.println("Name "+file.getName());
        String title = file.getName();
        String contentType = MimeTypesUtil.getContentType(file);
        DLFolder dlFolder;
        try{
            dlFolder = DLFolderLocalServiceUtil.getFolder(themeDisplay.getScopeGroupId(), 0, "Test");
        }catch(NoSuchFolderException e){
            System.out.println("1");
            dlFolder = DLFolderLocalServiceUtil. createDLFolder(themeDisplay.getScopeGroupId());
            try {
                dlFolder.setGroupId(themeDisplay.getUser().getGroupId());
            } catch (PortalException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            } catch (SystemException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
            dlFolder.setName("test");
            dlFolder.setCompanyId(themeDisplay.getCompanyId());
            dlFolder.setRepositoryId(themeDisplay.getUserId());
            dlFolder.setCreateDate(new Date());
            dlFolder.setModifiedDate(new Date());
            dlFolder.setParentFolderId(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
             try {
                dlFolder = DLFolderLocalServiceUtil.addDLFolder(dlFolder);
            } catch (SystemException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

ServiceContext serviceContext = 
ServiceContextFactory.getInstance(DLFileEntry.class.getName(),actionRequest);
            System.out.println("3");
            Map<String, Fields> fieldsMap = new HashMap<String, Fields>();
            System.out.println("4");
            long fileEntryTypeId = DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT;
            System.out.println("5");
            FileInputStream inputStream = new FileInputStream(file);
            System.out.println("6");

            DLFileEntry dlFileEntry = DLFileEntryLocalServiceUtil.addFileEntry(themeDisplay.getUserId(),themeDisplay.getScopeGroupId(), dlFolder.getRepositoryId(), 
                                            dlFolder.getFolderId(), title, contentType, title, "fileDesc", "sss",
                                            fileEntryTypeId, fieldsMap, file, inputStream, file.length(), serviceContext);
            System.out.println("7");
            inputStream.close();
            System.out.println("8");
            DLFileEntryLocalServiceUtil.updateFileEntry(themeDisplay.getUserId(), dlFileEntry.getFileEntryId(), title, contentType,
                        title, "fileDesc", "comment", true, dlFileEntry.getFileEntryTypeId(), fieldsMap, file, null, file.length(), serviceContext);
            System.out.println("9");

            DLFileEntry dlFile = DLFileEntryLocalServiceUtil.getFileEntry(themeDisplay.getScopeGroupId(), dlFolder.getGroupId(), title);

Original comment by ntanh...@gmail.com on 22 Jul 2014 at 2:11

GoogleCodeExporter commented 9 years ago
Check out this link
http://www.liferay.com/community/forums/-/message_boards/message/13224298

Original comment by ntanh...@gmail.com on 22 Jul 2014 at 2:17

GoogleCodeExporter commented 9 years ago
Add file to image gallery:
http://java-liferay.blogspot.com/2012/10/how-to-add-file-to-media-gallery.html

Original comment by ntanh...@gmail.com on 22 Jul 2014 at 2:25

GoogleCodeExporter commented 9 years ago
https://www.liferay.com/community/forums/-/message_boards/message/15562794

Original comment by ntanh...@gmail.com on 22 Jul 2014 at 2:33

GoogleCodeExporter commented 9 years ago
Duplication tittle FileEntry when using the same file for two DLFileEntry
Solved it by 
http://stackoverflow.com/questions/5136564/document-processing-in-liferay-portal

Original comment by ntanh...@gmail.com on 22 Jul 2014 at 2:50

GoogleCodeExporter commented 9 years ago
DLFileEntry, DLFolder were service on Document and Media portlet on Liferay 
Portal. It was used for manage upload and download files on the portlet. The 
file which was manage by these service is manage permission by user, group, 
scope group...
The table database use for store information is DLFileEntry, DLFolder...
The real file will be stored in folder path /opt/liferay/data/document_library/

Original comment by ntanh...@gmail.com on 23 Jul 2014 at 4:15

GoogleCodeExporter commented 9 years ago
<aui:input type="file" name="field2" multiple="multiple" >
3<aui:validator name="acceptFiles">
4        'jpg, png'
5    </aui:validator>

Original comment by ntanh...@gmail.com on 29 Sep 2014 at 3:40