diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java index 997a04905..e1d3a94b1 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/SingleLogEntryDisplayController.java @@ -210,6 +210,12 @@ protected void finalize() { fileAttachment.setContentType(attachment.getContentType()); fileAttachment.setThumbnail(false); fileAttachment.setFileName(attachment.getName()); + // Determine file extension, needed to support transition to Image Viewer app for image attachments + String fileExtension = ""; + int indexOfLastDot = attachment.getName().lastIndexOf('.'); + if(indexOfLastDot > -1){ + fileExtension = attachment.getName().substring(indexOfLastDot); + } // A bit of a hack here. The idea is to create a temporary file with a known name, // i.e. without the random file name part. // Files.createdTempFile does not support it, so a bit of workaround is needed. @@ -217,14 +223,14 @@ protected void finalize() { // This creates a temp file with a random part Path random = Files.createTempFile(attachment.getId(), attachment.getName()); // This does NOT create a file - Path nonRandom = random.resolveSibling(attachment.getId()); + Path nonRandom = random.resolveSibling(attachment.getId() + fileExtension); if(!Files.exists(nonRandom.toAbsolutePath())){ // Moves the temp file with random part to file with non-random part. nonRandom = Files.move(random, nonRandom); Files.copy(logClient.getAttachment(logEntry.getId(), attachment.getName()), nonRandom, StandardCopyOption.REPLACE_EXISTING); - fileAttachment.setFile(nonRandom.toFile()); nonRandom.toFile().deleteOnExit(); } + fileAttachment.setFile(nonRandom.toFile()); } catch (LogbookException | IOException e) { Logger.getLogger(SingleLogEntryDisplayController.class.getName()) .log(Level.WARNING, "Failed to retrieve attachment " + fileAttachment.getFileName(), e);