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.