Page cover

๐ŸŒ„Upload Content Attachment

In this article, I would be showing you how to upload an attachment in a Confluence content using the "go-atlassian" library.

Step 1: Set up the project

  1. Create a new directory for your project.

  2. Open a terminal and navigate to the project directory.

  3. Initialize a new Go module using the following command:

go mod init <module-name>

Step 2: Install the "go-atlassian" library

In the terminal, run the following command to install the "go-atlassian" library:

go get -v github.com/ctreminiom/go-atlassian

Step 3: Import the necessary packages

  1. Create a new Go file (e.g., main.go) in your project directory.

  2. Open the file and import the required packages:

package main

import (
	"github.com/ctreminiom/go-atlassian/confluence"
	"log"
	"os"
)

Step 4: Authenticate with Confluence

In the main function, create a new Confluence client and authenticate using your Atlassian URL, username, and API token:

Step 5: Upload an attachment to a Confluence page

  • Define the necessary variables for the page ID, file path, and file name:

  • Open the file using the provided file path:

  • Upload the attachment using the Content.Attachment.Create()method and provide the page ID, file name, and file content:

Make sure to replace <CONFLUENCE_PAGE_ID>, <FILE_PATH>, and <FILE_NAME> with the actual values for your use case.

Step 6: Run the program

  1. Save the main.go file.

  2. In the terminal, navigate to your project directory.

  3. Execute the following command to run the program:

This will upload the specified file as an attachment to the Confluence page with the provided page ID.

Last updated

Was this helpful?