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
Community Members
Community Events
Community Groups

/rest/api/3/issue/{issue-key}/attachments, upload file with a Chinese name, name turn to messy code

/rest/api/3/issue/{issue-key}/attachments, upload file with a Chinese name, name turn to messy code

I try this with Unirest http client

String imageAPIEndpoint = "",
File f = new File("D:\\中文.png");
InputStream in =new FileInputStream(f);
String fileName = f.getName();
HttpResponse<JsonNode> uploadResponse =


abc中文 turn to abc?? ( or other messy code) 

1 answer

1 accepted

0 votes
Answer accepted


I did a quick check on the API endpoint to make sure the call would go through without an issue and doing a direct Curl to the endpoint is working without triggering this behavior, so error you are encountering looks to be something in the formatting of the Unirest input values.

Testing this out I used the following CURL format with a cloud API token for basic auth:

curl -D- -u user:token -X POST -H "X-Atlassian-Token: no-check" -F "file=@中文.png"

And the file uploaded correctly without converting the non-ASCII values to question marks:

Screen Shot 2019-04-30 at 11.57.53 AM.png

I did not have the maven library installed to do a full test but looking at the documentation for Unirest at the following link:

It looks like it may be the formatting for the file input string missing some parenthesis as the example is:

.field("file", new File("/tmp/file"))

Can you try modifying the script to 


And if that does not work try removing the "in" variable and test with a direct syntax input to see if we can bypass the issue with something like:

HttpResponse<JsonNode> uploadResponse =


Hi, Earl:

Thanks so much for the detailed reply.

I tested the endpoint /rest/api/3/issue/{issue-key}/attachments with curl and postman, and that worked fine.

Finally, I found the reason of the "messy code".

It's a defect  of com.mashape.unirest 1.4.9


I try io.github.openunirest open-unirest-java 3.3.06

<!-- -->

This lib works  perfectly.


Thanks again for the quick reply and I hope this may help other friends.

Best Regards


Like Earl McCutcheon likes this

Thanks for sharing the follow up info, that was really helpful :)

You can change File name

I use okhttp


OkHttpClient client = new OkHttpClient.Builder()
.authenticator(getAuthenticator(userId, password))

RequestBody body = new MultipartBody.Builder()
.addFormDataPart("file", file.getOriginalFilename(), RequestBody.create(MediaType.parse("application/octet-stream"), file.getBytes()))
// .addFormDataPart("file", file.getOriginalFilename(), RequestBodyUtil.create(MediaType.parse("application/octet-stream"), f))

Request request = new Request.Builder()
.method("POST", body)
.addHeader("Accept", "application/json;charset=UTF-8")
.addHeader("X-Atlassian-Token", "no-check")

private static Authenticator getAuthenticator(final String userId, final String password){
return (route, response) ->{
String credential = Credentials.basic(userId, password);
return response.request().newBuilder().header("Authorization", credential).build();

Suggest an answer

Log in or Sign up to answer

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