Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,559,632
Community Members
 
Community Events
185
Community Groups

Downloading xlsx or png from Jira via API creates corrupted file

I am using the Jira api to pull down attachments from our Jira Server instance. I am finding the files I pull down and save are corrupted if they are anything but txt files.  
Below is my code fragment that works for pulling down txt files:
String url = "https://" + serverName + "/rest/api/2/attachment/" + attId;
String response = executeGet(url, false);
if (response != null){
JsonUtil ju = new JsonUtil(response, false);
org.json.simple.JSONObject attachmentInfo = ju.getJsonMessage();
String mimeType = (String)attachmentInfo.get("mimeType");
String contentUrl = (String)attachmentInfo.get("content");
String filename = (String)attachmentInfo.get("filename");
try {
URL fileUrl = new URL(contentUrl);
try (InputStream in = fileUrl.openStream()) {
Files.copy(in, Paths.get(filename));
}
} catch (Exception e) {
logger.error("Unable to download file from " + contentUrl);
}
}
I have used the File.copy before to pull down pngs from the other sites with no problem. Any advice would be great.

2 answers

1 accepted

0 votes
Answer accepted

I was able to resolve the issue, I changed to code to use URLConnection instead of HTTPConnection and that worked

0 votes
Dan Breyen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 10, 2023

 Hi David, I looked in Atlassian's JIRA site and didn't find anything specific to this issue (either open or closed).  In the future, you can search their site for issues at jira.atlassian.com.  If you can replicate it(and it sounds like you can), I would enter a support ticket with atlassian at support.atlassian.com and see what they say.  I know it's server, so I'm not sure if they'll fix it or not.  They also might know of a version that there is a fix in, as I see you're not on the latest code.

Thanks for the advice, I have done so, I typically double up my requests bc the Community is usually quicker than support.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.10
TAGS
AUG Leaders

Atlassian Community Events