You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Function addJIRA_Attachment(sURL)
' MSGBOX sCookie
Const STR_BOUNDARY = "abc123-xyz123"
sPath ="C:/Users/PB/JiraTest.xlsx"
fileType = "binary"
fileName="JiraTest.xlsx"
base64Encoded = convertFileToBase64(sPath)
getFilebyte = GetFileBytes(sPath)
request = "--" & STR_BOUNDARY & vbCrLf
request = request & "Content-Disposition: form-data; name=""file""; filename=" & fileName & "" & vbCrLf
request = request & "Content-Type: application/octet-stream" & vbCrLf
request = request & "Content-Transfer-Encoding: base64" & vbCrLf & vbCrLf
request = request & getFilebyte & vbCrLf
request = request & "--"& STR_BOUNDARY&"--"
Set JiraService = CreateObject("MSXML2.XMLHTTP.6.0")
With JiraService
.Open "POST", sURL & "rest/api/2/issue/GTAUIAF-19/attachments", False
.setRequestHeader "X-Atlassian-Token:" , "nocheck"
'.Open "GET", sURL & "rest/api/2/attachment/meta", False
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & STR_BOUNDARY
' .setRequestHeader "Content-Length", Len(request)
' .setRequestHeader "Accept", "application/json"
.setRequestHeader "Set-Cookie", sCookie
.send Stream_StringToBinary(request)
' msgbox .status
msgbox .responseText
m_sJSONString = .responseText
If .Status <> 400 or .Status<>404 Then
m_sJSONString = .responseText
Else
m_sJSONString = "Check the json string or url or your user id and password"
End If
keyval = Split(m_sJSONString,",")
For k = 0 to Ubound(keyval)
If Instr(keyval(k),"""key"":""")>0 Then
strval = split(keyval(k),":")
curTestkey = Replace(strval(1),"""","")
End If
Next
End With
Set JiraService= Nothing
End Function
Function getJiraSessionId(sURL,sJIRAUserID,sJIRAPass)
Set JiraAuth = CreateObject("MSXML2.XMLHTTP.6.0")
With JiraAuth
.Open "POST", sURL & "rest/auth/1/session", False
.setRequestHeader "X-Atlassian-Token:" , "nocheck"
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.send " {""username"" : """& sJIRAUserID &""", ""password"" : """& JIRA_PWD &"""}"
sOutput = .responseText
sCookie = "JSESSIONID=" & Mid(sOutput, 42, 32) & "; Path=/Jira"
End With
End Function
Function GetFileBytes(fileName)
Dim objStream
sType="binary"
Set objStream = CreateObject("ADODB.Stream")
objStream.Type=1
objStream.Open
objStream.LoadFromFile fileName
getbinaryArray=objStream.Read 'read binary'
msgbox TypeName(getbinaryArray)
objStream.Close
GetFileBytes=SimpleBinaryToString(getbinaryArray)
Set objStream = Nothing
end function
Function SimpleBinaryToString(Binary)
Dim I, S
For I = 1 To LenB(Binary)
S = S & Chr(AscB(MidB(Binary, I, 1)))
Next
SimpleBinaryToString = S
msgbox SimpleBinaryToString
End Function
Function Stream_StringToBinary(Text)
Const adTypeText = 2
Const adTypeBinary = 1
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeText
BinaryStream.CharSet = "us-ascii"
BinaryStream.Open
BinaryStream.WriteText Text
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary
BinaryStream.Position = 0
Stream_StringToBinary = BinaryStream.Read
Set BinaryStream = Nothing
End Function