简体   繁体   English

如何使用 Liferay 将多个文件下载为 zip 文件?

[英]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.我在 Liferay 平台内的文档和媒体 portlet 中使用“多文件下载”功能。 However, it downloads all the files separately.但是,它会单独下载所有文件。

I am using Liferay 6.1 .我正在使用 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.我想修改该功能,以便当我选择多个文件并单击下载功能时,它会将所有这些文件下载为一个单独的 zip 文件。 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.我试图部署一个 liferay-hook,但我得到了 BUILD FAILED。

source :来源 :

http://www.surekhatech.com/blog/multiple-file-download-for-liferay-documents-and-media-display-portlet 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.我不想覆盖liferay 的documents-and-media-display-portlet。

I'm trying to copy paste code from project of blog.我正在尝试从博客项目中复制粘贴代码。 I have problem with my view.jsp .我的 view.jsp 有问题。

what I should take from source code and add in my view?我应该从源代码中获取什么并添加到我的视图中?

My view.jsp:我的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.您没有说明您使用的 Liferay 门户版本、您尝试过的内容等。所有这些信息都将帮助我们为您提供更好的答案。

From what I gather you are using the multiple file download option in Liferay's document library.据我所知,您正在使用 Liferay 文档库中的多文件下载选项。 The Liferay portal does not provide a way to download multiple files as a zip bundle out-of-the-box. Liferay 门户不提供一种将多个文件作为开箱即用的 zip 包下载的方法。 When Liferay doesn't provide something out-of-the-box you usually need to write a Java hook to override and extend the functionality.当 Liferay 不提供开箱即用的东西时,您通常需要编写一个 Java 钩子来覆盖和扩展功能。

However....然而....

This hook has already been developed by a company called Surekha technologies.该挂钩已由一家名为 Surekha 技术的公司开发。 It is available for free to download from the Liferay marketplace.它可以从 Liferay 市场免费下载。

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

It states one of the key benefits is "Bundled in ZIP format to reduce download size"它指出主要好处之一是“以 ZIP 格式捆绑以减少下载大小”

You can either download it through the marketplace service portlet in your portal or you can download the deployment file and deploy it yourself.您可以通过门户中的市场服务 portlet 下载它,也可以下载部署文件并自行部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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