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

Pritha
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 4, 2021

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