![](/img/trans.png)
[英]Download multiple files in parallel to a zip-file from S3 using Java
[英]How to download multiple files as a zip-file using Liferay?
我在 Liferay 平台内的文档和媒体 portlet 中使用“多文件下载”功能。 但是,它会单独下载所有文件。
我正在使用 Liferay 6.1 。
我想修改该功能,以便当我选择多个文件并单击下载功能时,它会将所有这些文件下载为一个单独的 zip 文件。 这可能吗? 如果是这样,如何实现这样的目标?
我试图部署一个 liferay-hook,但我得到了 BUILD FAILED。
来源 :
我不想覆盖liferay 的documents-and-media-display-portlet。
我正在尝试从博客项目中复制粘贴代码。 我的 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>
您的问题非常广泛且不具体。 您没有说明您使用的 Liferay 门户版本、您尝试过的内容等。所有这些信息都将帮助我们为您提供更好的答案。
据我所知,您正在使用 Liferay 文档库中的多文件下载选项。 Liferay 门户不提供一种将多个文件作为开箱即用的 zip 包下载的方法。 当 Liferay 不提供开箱即用的东西时,您通常需要编写一个 Java 钩子来覆盖和扩展功能。
该挂钩已由一家名为 Surekha 技术的公司开发。 它可以从 Liferay 市场免费下载。
https://web.liferay.com/marketplace/-/mp/application/36077428
它指出主要好处之一是“以 ZIP 格式捆绑以减少下载大小”
您可以通过门户中的市场服务 portlet 下载它,也可以下载部署文件并自行部署。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.