Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

I want to include attachments when creating a confluence page.

sciamat September 25, 2022

hello

When I create a confunece page using scriptrunner
I want to put the attachments together.

 

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.spaces.Space
import com.atlassian.confluence.spaces.SpaceManager
import com.atlassian.confluence.pages.Attachment
import com.atlassian.confluence.pages.AttachmentManager

import com.atlassian.sal.api.component.ComponentLocator

import java.io.ByteArrayInputStream

import org.apache.log4j.Logger
import org.apache.log4j.Level

def logger = Logger.getLogger("AAA")
logger.setLevel(Level.DEBUG)

def spaceManager = ComponentLocator.getComponent(SpaceManager)
def pageManager = ComponentLocator.getComponent(PageManager)

// space info
def spaceKey = "~test"
def space = spaceManager.getSpace("${spaceKey}")
def homePage = space.getHomePage()

// create parent page
Page parentPageObj = pageManager.getPage(homePage.id)
Page parentPage = new Page()

parentPage.setSpace(space)
parentPage.setParentPage(parentPageObj)
parentPage.setTitle("parent page")
parentPage.setBodyAsString("null")

parentPageObj.addChild(parentPage)

pageManager.saveContentEntity(parentPage, null, null)

 

// create sub page
// attachment file
String filename = """/efs_data/atlassian/shared-home/confluence-shared-home/confluence.cfg.xml"""
Attachment newFile = new Attachment(filename, "text/csv", 6014, "new file");

Page subPageObj = pageManager.getPage(parentPage.id)
Page subPage = new Page()

subPage.setSpace(space)
subPage.setParentPage(subPageObj)
subPage.setTitle("sub page")
subPage.setBodyAsString("null")
subPage.addAttachment(newFile)

subPageObj.addChild(subPage)

pageManager.saveContentEntity(subPage, null, null)

 

 

 

filename contains the entire path and file name.

 

filename contains the entire path and file name.

I want to upload all files in a folder that confluence has access to.

I'd appreciate it if you could tell me how.

0 comments

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events