Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the Comment in a Confluence REST Attachment Import

Jeff Abbott May 19, 2020

I have VBA code I am using to import auto-generated chart images from Excel. I want to include a comment with each import. I am able to import the images w/o a problem. I can set the comment using curl, but the intent is to do this w/o curl.  The code I'm using started from another community post.

My code is below:

Public Function update_Attachement(strPgID As String, strAttachmentID As String, strFileURI As String) As String
Dim strFullURL As String
Dim strCURLoptions As String
Dim strHTTPstatus As String
Dim shlCmdPrpt As New WshShell
Dim strUsID As String
Dim strPWD As String
Dim strServerURL As String
Dim strCURLexecutable As String
Dim strResponseText As String
Dim sFileDataStr As String

Const STR_BOUNDARY As String = "abc123-xyz123"
' Debug.Print "Load "; strFileURI

mainSheet.Description = "Loading: " & strFileURI
strUsID = getConfig(JIRA_USER)
strPWD = getConfig(JIRA_PWD)
strServerURL = getConfig(CONFLUENCE_URL)
strCURLexecutable = getConfig(CURL_PATH)

If Len(strAttachmentID) Then
strFullURL = strServerURL & "/rest/api/content/" & strPgID & "/child/attachment/" & strAttachmentID & "/data"
Else
strFullURL = strServerURL & "/rest/api/content/" & strPgID & "/child/attachment"
End If

sFileDataStr = "--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=""file"";Filename = """ & Mid$(strFileURI, InStrRev(strFileURI, "\") + 1) & """" & vbCrLf & _
"Content-Type: application/octet-stream" & vbCrLf & _
vbCrLf & GetFileBytes(strFileURI) & vbCrLf & "--" & STR_BOUNDARY & "--"

With oConfluenceService
.Open "POST", strFullURL, False
.setRequestHeader "X-Atlassian-Token", "nocheck"
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & STR_BOUNDARY
.setRequestHeader "Authorization", "Basic " & EncodeBase64(getConfig(JIRA_USER) & ":" & getConfig(JIRA_PWD))
.setRequestHeader "Set-Cookie", sCookie
.Send stringToByteArray(sFileDataStr)
strResponseText = .responseText
strHTTPstatus = .Status
End With

add_AttachementToConfluenceByID = strHTTPstatus

Select Case strHTTPstatus
Case "200" ' OK
mainSheet.Description = "Loaded: " & strFileURI
Case Else
WriteResponse strResponseText, Me.CodeName
Debug.Print "Could not attach file: " & strFileURI & " to confluence page, HTTP status: " & strHTTPstatus & "."
End Select
End Function

0 answers

Suggest an answer

Log in or Sign up to answer