Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,360,201
Community Members
 
Community Events
168
Community Groups

I am able to attach excel file in JIRA with UFT, but while opening from Jira, saying format is wrong

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

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

189 views 1 6
Read article

Atlassian Community Events