From 9657e74e8b2a92a2bb038d80d17c0f4f41879a7e Mon Sep 17 00:00:00 2001 From: Spiros Dimopulos Date: Thu, 26 Feb 2026 20:04:44 +0200 Subject: [PATCH] =?utf8?q?NO-JIRA:=20added=20removeing=20query=20parameter?= =?utf8?q?s=20from=20filename=20when=20download=E2=80=A6=20(#506)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit NO-JIRA: added removeing query parameters from filename when downloading file; --- .../services/common/HttpDownloadUtility.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/HttpDownloadUtility.java b/services/common/src/main/java/org/collectionspace/services/common/HttpDownloadUtility.java index 9e9c865ce..fff647523 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/HttpDownloadUtility.java +++ b/services/common/src/main/java/org/collectionspace/services/common/HttpDownloadUtility.java @@ -42,7 +42,7 @@ public class HttpDownloadUtility { } return null; } - + return destDir; } @@ -54,7 +54,7 @@ public class HttpDownloadUtility { if (tmpdir.endsWith(File.separator) == false) { tmpdir = tmpdir + File.separator; } - + String destDir = getDestDir(tmpdir + UUID.randomUUID() + File.separator); String filePath = downloadFile(fileURL, destDir); result = new File(filePath); @@ -62,13 +62,13 @@ public class HttpDownloadUtility { String msg = String.format("Could not download file use this URL: %s", fileURL); logger.error(msg, e); } - + return result; } - + /** * Downloads a file from a URL - * + * * @param fileURL HTTP URL of the file to be downloaded * @param saveDir path of the directory to save the file * @throws IOException @@ -81,7 +81,7 @@ public class HttpDownloadUtility { try { httpResponseCode = httpConn.getResponseCode(); - + // always check HTTP response code first if (httpResponseCode == HttpURLConnection.HTTP_OK) { String fileName = ""; @@ -96,8 +96,13 @@ public class HttpDownloadUtility { } else { // extracts file name from URL fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1, fileURL.length()); + // Remove query parameters from filename + int qIndex = fileName.indexOf("?"); + if (qIndex > -1) { + fileName = fileName.substring(0, qIndex); + } } - + if (logger.isDebugEnabled()) { String contentType = httpConn.getContentType(); int contentLength = httpConn.getContentLength(); @@ -105,15 +110,15 @@ public class HttpDownloadUtility { logger.debug("Disposition is:" + disposition != null ? disposition : ""); logger.debug("Content type is:" + contentType != null ? contentType : ""); logger.debug("Content length is:" + contentLength); - } + } // opens input stream from the HTTP connection InputStream inputStream = httpConn.getInputStream(); String saveFilePath = saveDir + File.separator + fileName; //FIXME: File.separator NOT needed - + // opens an output stream to save into file FileOutputStream outputStream = new FileOutputStream(saveFilePath); - + try { int bytesRead = -1; byte[] buffer = new byte[BUFFER_SIZE]; -- 2.47.3