Issues with downloading Jira attachments through REST API for specific file formats

I’m experiencing difficulties when attempting to download attachments from Jira using the REST API. My workflow involves calling /rest/api/2/attachment/{id} to retrieve the attachment details. I extract the “content” field that gives me the download URL, and then I proceed to send a GET request using basic authentication.

Interestingly, I can download PNG images without any issues, but for other file types like TXT files, JPEG images, and Microsoft documents, I receive an HTML response that prompts me to log in instead of getting the files directly.

Here’s the code I’m currently using:

CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet request = new HttpGet(downloadUrl);
request.setHeader("Authorization", "Basic " + base64EncodedCredentials);
CloseableHttpResponse response = httpClient.execute(request);

I am using Java with Spring to integrate with Jira. The authentication seems to work for PNG files but fails with other formats. Has anyone faced this issue before?

I hit something similar with our internal Jira. Turned out to be XSRF protection - Jira handles different MIME types differently for security. Adding the X-Atlassian-Token header with “no-check” fixed my auth redirects for non-image files. Some orgs also make Jira require extra verification for potentially executable stuff like docs and text files. I’d double-check your base64 encoding and try the same request in Postman first - helps figure out if it’s your code or the server config.

This is a content disposition issue mixed with Jira’s security policies. I ran into the same thing last year - Jira serves different file types with different content-disposition headers based on security settings. PNG files usually get whitelisted for inline display, but text files and documents get forced downloads or redirected to login pages. Try setting the User-Agent header to look like a browser request - some Jira instances block API-style requests for certain file types. Also check if your credentials expired between requests, since the attachment metadata call and actual download are separate operations with different timeout windows.

maybe it’s a session timeout or some cookie issues. try adding an Accept: */* header too. also, check if your JIRA has any content-type filtering. testing with curl could help figure out if the problem is in your code or JIRA settings.