Insert an image into Confluence page via dynamic content macro


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

@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="">
<head th:insert="~{layout :: atlassianConnectResources}">
    <meta charset="UTF-8">
<body class="aui-page-hybrid">
<section id="content" role="main">
    <img th:src="${imageUrl}" alt="imageName" style="width:304px;height:228px;">

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:

    @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";
            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

You’re running your addon as a web site. You should reference your image relative to the root of the site you’re running. Is there a reason that you’re not doing that and trying the binary approach?

I’ll make an assumption to the root folder of your site, change this:




I tried using a relative path before, but it didn’t work so I thought I have to use the absolute path. And after that didn’t work I thought about the byte array because I just want to return the image to the macro and it is not a requirement that html is used.

The path of my macro controller is:


I tried using the assumed path of yours and some other combinations but it didn’t work.