![](/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.