It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Doris I'm New Here Nov 04, 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 Nov 05, 2019

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

308 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you