Hey,
my goal is to show and insert a locally stored picture in a confluence page by using a dynamic content macro.
I currently use Atlassian Connect Spring Boot, but if anyone have a solution using Express that’s okay too.
My problem is the following, if I use the printImageMacro
inside my dynamic macro controller
@ResponseBody
@GetMapping(value="/spring/macro/static/print-image-macro", produces = MediaType.IMAGE_JPEG_VALUE)
public String printImageMacro(Model model) {
String imageUrl = "C:/Workspace/src/NT/research-atlassian-connect/Spring-Boot-Connect/atlassian-connect-spring-boot/src/main/resources/falloutVaultBoyThumbsUp.jpg";
model.addAttribute("imageUrl", imageUrl);
return "dynamicPrintImageMacro";
}
which returns the following html file to atlassian:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:insert="~{layout :: atlassianConnectResources}">
<meta charset="UTF-8">
<title>PrintImageMacro</title>
</head>
<body class="aui-page-hybrid">
<section id="content" role="main">
<img th:src="${imageUrl}" alt="imageName" style="width:304px;height:228px;">
</section>
</body>
</html>
It works just fine, as long as the value of the imageUrl
variable contains a public url.
But I replace the public url with a local url (absolute path to the file C:/workspace/img.jpg) it doesn’t work anymore.
So I thought about returning the image directly as an Byte array. But all I get to see in my Confluence Page after inserting the macro is the Byte array as a String.
Here the code I used for returning the Byte array:
@ResponseBody
@GetMapping(value="/spring/macro/static/print-image-macro", produces = MediaType.IMAGE_JPEG_VALUE)
public byte[] printImageMacro(Model model) {
String imageUrl = "C:/Workspace/src/NT/research-atlassian-connect/Spring-Boot-Connect/atlassian-connect-spring-boot/src/main/resources/falloutVaultBoyThumbsUp.jpg";
try{
Path path = Paths.get(imageUrl);
return Files.readAllBytes(path);
}catch(IOException e){
throw new RuntimeException(e);
}
}
Why is the byte array not converted to the image?
Is there an other way to insert an image into a confluence page via a dynamic content macro?
Best regards
Nico