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,300,979
Community Members
 
Community Events
165
Community Groups

Scriptrunner special characters in attachment's filename encoding

Edited

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, new String(fileNameData.getBytes("UTF-8"), "UTF-8"))
.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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
Community showcase
Published in Jira Software

An update on Jira Software customer feedback – June 2022

Hello Atlassian Community! Feedback from customers like you has helped us shape and improve Jira Software. As Head of Product, Jira Software, I wanted to take this opportunity to share an update on...

177 views 2 5
Read article

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