diff --git a/src/main/java/org/bioimageanalysis/icy/deeplearning/versionmanager/downloading/DeepLearningVersionDownloader.java b/src/main/java/org/bioimageanalysis/icy/deeplearning/versionmanager/downloading/DeepLearningVersionDownloader.java index c6f5626d044cf4959816fd651e6eca2a1d9bf676..e55cfc83420891ed635665c56e7200d96560ebf8 100644 --- a/src/main/java/org/bioimageanalysis/icy/deeplearning/versionmanager/downloading/DeepLearningVersionDownloader.java +++ b/src/main/java/org/bioimageanalysis/icy/deeplearning/versionmanager/downloading/DeepLearningVersionDownloader.java @@ -253,7 +253,6 @@ public class DeepLearningVersionDownloader private static Path downloadFile(String urlString, Path targetDirectory, ProgressListener progressListener) throws IOException { - URL url = new URL(urlString); Path localFilePath = toLocalVersionFile(targetDirectory, urlString); Files.deleteIfExists(localFilePath); @@ -261,8 +260,16 @@ public class DeepLearningVersionDownloader try { HttpURLConnection httpConnection = (HttpURLConnection) (url.openConnection()); - long completeFileSize = httpConnection.getContentLength(); - + while (httpConnection.getResponseCode() == 302) { + url = new URL(httpConnection.getHeaderField("Location")); + httpConnection = (HttpURLConnection) (url.openConnection()); + } + long completeFileSize = httpConnection.getContentLengthLong(); + if (completeFileSize == -1) { + progressListener.notifyProgress(1, 1); + return downloadFile(urlString, targetDirectory); + } + completeFileSize = 1; try (BufferedInputStream in = new BufferedInputStream(httpConnection.getInputStream())) { FileOutputStream fos = new FileOutputStream(localFilePath.toFile());