简体   繁体   中英

How to download multiple files as a zip-file using Liferay?

Problem Statement

I am using the "multiple file download" function in the documents and media portlet inside the Liferay platform. However, it downloads all the files separately.

I am using Liferay 6.1 .

Question

I would like to modify the functionality so that when I select multiple files and click the download function it downloads all those files as one single zip file. Is this possible? If so how would something like this be achieved?

Update

I tryed to deploy a liferay-hook but i got BUILD FAILED.

source :

http://www.surekhatech.com/blog/multiple-file-download-for-liferay-documents-and-media-display-portlet

I don't want to override the documents-and-media-display-portlet of liferay.

I'm trying to copy paste code from project of blog. I have problem with my view.jsp .

what I should take from source code and add in my view?

My view.jsp:

<c:choose>
    <c:when test="${fn:length(listFiles) gt 0}">
        <div class="lfr-search-container " id="flash-table"> 
            <% 
                PortletURL actionURL = renderResponse.createRenderURL(); 
                List<DLFileEntry> list = (List<DLFileEntry>) request.getAttribute("listFiles");
                DateFormat dateFormat = new SimpleDateFormat("MMM yyyy");

                OrderByComparator orderByComparator = OrderByComparatorFactoryUtil.create("DLFileEntry", "modifiedDate", false);
                Collections.sort(list,orderByComparator);
            %>
            <liferay-ui:search-container iteratorURL="<%= actionURL %>" delta="10" emptyResultsMessage="no-documents">
                <liferay-ui:search-container-results total="<%= list.size() %>" results="<%= ListUtil.subList(list, searchContainer.getStart(), searchContainer.getEnd()) %>" />
                <liferay-ui:search-container-row modelVar="file" className="DLFileEntry">
                    <%
                        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
                        String pdfUrl = "", excelUrl = "";
                        String logo ="", vendor="", technology="", productType="", flashType="";

                        long globalGroupId = GroupLocalServiceUtil.getCompanyGroup(PortalUtil.getDefaultCompanyId()).getGroupId();

                        if(file.getExtension().equalsIgnoreCase("pdf"))
                            pdfUrl = "<a target='_blank' href='"+ themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + globalGroupId + StringPool.SLASH + file.getUuid()+"' ><img src='/flash-table-portlet/images/pdf.png' width='20px'/> </a>";
                        else if(file.getExtension().equalsIgnoreCase("xlsx") || file.getExtension().equalsIgnoreCase("xls") || file.getExtension().equalsIgnoreCase("csv") )
                            excelUrl = "<a target='_blank' href='"+ themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + globalGroupId + StringPool.SLASH + file.getUuid()+"' ><img src='/flash-table-portlet/images/excel.png' width='20px'/> </a>";

                        try{
                            Map<String, Fields> fieldsMap = file.getFieldsMap(file.getFileVersion().getFileVersionId());
                            for (Fields fields : fieldsMap.values()) {
                                vendor =  fields.get("vendor").getValue().toString().replace("[\"", "").replace("\"]", "");
                                if(vendor.equalsIgnoreCase("other"))
                                    logo="<strong>other</strong>";
                                else
                                    logo = "<img src='/flash-table-portlet/images/vendor/"+vendor.toLowerCase()+".gif' style='max-width:120px' />";
                                technology= fields.get("technology").getValue().toString().replace("[\"", "").replace("\"]", "");
                                productType =  fields.get("producttype").getValue().toString().replace("[\"", "").replace("\"]", "");
                                flashType =  fields.get("flashtype").getValue().toString().replace("[\"", "").replace("\"]", "");
                            }
                        }catch(Exception ex){
                            ex.printStackTrace();
                        }
                    %>
                    <liferay-ui:input-checkbox param="<%= file.getName() %>" cssClass="check"></liferay-ui:input-checkbox>
                    <liferay-ui:search-container-column-text name='date' cssClass="txt-capitalize width-10" value="<%= dateFormat.format(file.getModifiedDate()) %>" />
                    <liferay-ui:search-container-column-text name='vendor' cssClass="width-10" value="<%= logo %>" />
                    <liferay-ui:search-container-column-text name='technology' cssClass="width-10" value="<%= technology %>" />
                    <liferay-ui:search-container-column-text name='product-type' cssClass="width-12"  value="<%= productType %>" />
                    <liferay-ui:search-container-column-text name='flash-type' cssClass="width-12"  value="<%= flashType %>" />
                    <liferay-ui:search-container-column-text name='model' cssClass="width-25"  value="<%= file.getTitle() %>" />
                    <liferay-ui:search-container-column-text name='executive-summary' cssClass="width-10" value="<%= pdfUrl %>" />
                    <liferay-ui:search-container-column-text name='excel-file' cssClass="width-10" value="<%= excelUrl %>" />

                    <script type="text/javascript">
                    $('.check').click(function() {
                    <%! List<String> multi_files_urls; %>
                    $(".check").each(function(){
                        if($(this).is(":checked")){
                        <%
                        FileEntry fileEntry = DLAppServiceUtil.getFileEntry(file.getFileEntryId());
                        FileVersion fileVersion = fileEntry.getFileVersion();
                        String queryString = "";
                        boolean appendFileEntryVersion = true;
                        boolean useAbsoluteURL = true;
                        String dlURL = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, queryString, appendFileEntryVersion, useAbsoluteURL);
                        multi_files_urls.add(dlURL); 
                        %>
                      }
                    });
                    </script>
                </liferay-ui:search-container-row>
                <liferay-ui:search-iterator searchContainer="<%= searchContainer %>" paginate="${fn:length(listFiles) ge 10}" />
            </liferay-ui:search-container>
        </div><br /><br />


    </c:when>
    <c:otherwise>
        <div class="alert alert-warning text-center">
            <br /><liferay-ui:message key="no-documents"/><br /><br />
        </div>
    </c:otherwise>
</c:choose>

Your question is extremely broad and nonspecific. You don't state what Liferay portal version you are using, what you have tried, etc. All of that information will help us give you a better answer.

From what I gather you are using the multiple file download option in Liferay's document library. The Liferay portal does not provide a way to download multiple files as a zip bundle out-of-the-box. When Liferay doesn't provide something out-of-the-box you usually need to write a Java hook to override and extend the functionality.

However....

This hook has already been developed by a company called Surekha technologies. It is available for free to download from the Liferay marketplace.

https://web.liferay.com/marketplace/-/mp/application/36077428

It states one of the key benefits is "Bundled in ZIP format to reduce download size"

You can either download it through the marketplace service portlet in your portal or you can download the deployment file and deploy it yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM