Forums

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

upload attachment to JIRA via REST API,but attachment with chinese name shows like "???"

Doris
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!
November 4, 2019

I have upload a attachment with Chinese name, but it shows like "*???*", I use VBA to do that as following code (everything can worked except filename display error):

And this attachment Excel have macro, so i changed header "Content-Type: application/vnd.ms-excel.sheet.binary.macroEnabled.12", "StrConv(srcTxt, vbFromUnicode, 1033)", "1033"(en-us) i have try change to "2050"(zh-cn), but the attachment with macro can't be open.

help~~

 

Private Function sendAttachmentToJira(ByVal sPostData As String) As Boolean

Dim sFileDataStr As String
Const STR_BOUNDARY_U As String = "abc123-xyz123"
JiraSite = "https://ocoejira.johnsoncontrols.com"
JIRAuser = Sheet1.Range("B3").Value
JIRApassword = Sheet1.Range("B4").Value

sFileDataStr = "--" & STR_BOUNDARY_U & vbCrLf & _
"Content-Disposition: form-data; name=""file"";Filename = """ & Mid$(sPostData, InStrRev(sPostData, "\") + 1) & """" & vbCrLf & _
"Content-Type: application/vnd.ms-excel.sheet.binary.macroEnabled.12" & vbCrLf & _
vbCrLf & getFileBytes(sPostData) & vbCrLf & "--" & _
STR_BOUNDARY_U & "--"
'Content-Type: multipart/form-data

With JiraService
.Open "POST", JiraSite & "/rest/api/2/issue/" & issueKey & "/attachments", False
.setRequestHeader "X-Atlassian-Token", "nocheck"
.setRequestHeader "Content-Type", "multipart/form-data ; boundary=" & STR_BOUNDARY_U 'application/json
.setRequestHeader "Authorization", "Basic " & EncodeBase64(JIRAuser & ":" & JIRApassword)
' .SetRequestHeader "Set-Cookie", Token
.send stringToByteArray(sFileDataStr)
JIRAResponse = .responseText
If .Status = "200" Then sendAttachmentToJira = True
End With

ErrHander:
If Left(JiraService.Status, 1) = "4" Then MsgBox removeBrackets(JIRAResponse), vbCritical, "Adding attachments failed...": sendAttachmentToJira = False

End Function




Private Function stringToByteArray(srcTxt As String) As Byte()
stringToByteArray = StrConv(srcTxt, vbFromUnicode, 1033)
End Function

 

1 answer

0 votes
Doris
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!
November 5, 2019

so....   no one else had the same problem? ...

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events