The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Scriptrunner special characters in attachment's filename encoding

Lukáš Meitner
Contributor
June 2, 2022

Hi guys,

I am trying to synchronize attachments between two instances. I have this code:

def attachment = get("https://jira.atlassian.net/rest/api/3/attachment/content/{attachmentId}") // get the content binary data
.basicAuth("e-mail@address.com", "token")
.asBinary()
.body

def attachmentData = get("https://jira.atlassian.net/rest/api/3/attachment/{attachmentId}") // get the attachment metadata
.basicAuth("e-mail@address.com", "token")
.asObject(Map)
.body

def fileName = attachmentData['filename'] as String

InputStream stream = new ByteArrayInputStream(attachment.getBytes()) // create a file to send

def sendAttachment = post("/rest/api/3/issue/{issueID}/attachments")
.header("Accept", "application/json")
.header("X-Atlassian-Token", "no-check")
.field("file", stream, fileName)
.asJson()

I can upload the attachment into an issue, but if it's name contains special character like "Český jazyk.txt" it will replace the characters by "?", so the name of created attachment will be "?esk? jazyk.txt". And this is the problem I need to resolve.

Many thanks for any suggestions.

Lukas

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.