From 0b7f6c6d196317c33fcb3f04beb9944143377e4e Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Mon, 8 Oct 2018 09:49:26 +0000 Subject: [PATCH] ref 11720: DataMiner - Update to StorageHUB https://support.d4science.org/issues/11720 Updated to StorageHub git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/data-miner-manager-widget@172015 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../server/DownloadServlet.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/portlets/widgets/dataminermanagerwidget/server/DownloadServlet.java b/src/main/java/org/gcube/portlets/widgets/dataminermanagerwidget/server/DownloadServlet.java index 8dca29f..a834778 100644 --- a/src/main/java/org/gcube/portlets/widgets/dataminermanagerwidget/server/DownloadServlet.java +++ b/src/main/java/org/gcube/portlets/widgets/dataminermanagerwidget/server/DownloadServlet.java @@ -88,7 +88,7 @@ public class DownloadServlet extends HttpServlet { ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(req, scopeGroupId); StorageUtil filesStorage = new StorageUtil(); ItemDownload itemDownload = filesStorage.getItemDownload(serviceCredentials.getUserName(), itemId); - logger.debug("ItemDownload: "+itemDownload); + logger.debug("ItemDownload: " + itemDownload); if (itemDownload == null) { logger.error("This type of item does not support download operation"); throw new ServletException("This type of item does not support download operation"); @@ -101,27 +101,36 @@ public class DownloadServlet extends HttpServlet { String fileName; if (itemDownload.getItemDescription() == null) { fileName = "filename"; + resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\""); + resp.setHeader("Content-Type", "application/force-download"); } else { if (itemDownload.getItemDescription().getName() == null || itemDownload.getItemDescription().getName().isEmpty()) { if (itemDownload.getItemDescription().getType() != null && itemDownload.getItemDescription() .getType().compareTo(FolderItem.class.getSimpleName()) == 0) { fileName = "folder.zip"; + resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\""); + resp.setHeader("Content-Type", "application/zip"); } else { fileName = "filename"; + resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\""); + resp.setHeader("Content-Type", "application/force-download"); } } else { if (itemDownload.getItemDescription().getType() != null && itemDownload.getItemDescription() .getType().compareTo(FolderItem.class.getSimpleName()) == 0) { fileName = itemDownload.getItemDescription().getName() + ".zip"; + resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\""); + resp.setHeader("Content-Type", "application/zip"); + } else { fileName = itemDownload.getItemDescription().getName(); + resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\""); + resp.setHeader("Content-Type", "application/force-download"); } } } - logger.debug("DownloadServlet filename: "+fileName); - resp.setHeader("Content-Disposition:", "attachment;filename=\"" + fileName + "\""); - resp.setHeader("Content-Type", "application/force-download"); + logger.debug("DownloadServlet filename: " + fileName); stream(itemDownload.getInputStream(), resp.getOutputStream()); } }