Download and store files from Jira using the jira-ruby gem in Rails

Downloading Jira Files with jira-ruby Gem

I’m working on a Rails application and need to fetch files from our Jira instance. I want to use the jira-ruby gem to download attachment files through their REST API.

Has anyone successfully used this gem to retrieve and save attachment files? I’m specifically looking at the attachment content endpoint that follows the pattern /rest/api/2/attachment/content/{file_id}.

I’m wondering if I can use the standard .get method from the gem or if there’s a better approach for handling file downloads. Any code examples or guidance would be really helpful.

I’ve been struggling with this for a while and can’t find clear documentation on downloading actual file content versus just getting attachment metadata.

yep, .get should work for that! just make sure you handle the binary data right. set your headers correctly and use response.body to get the file content. after that, you can save it in any way u prefer, like File.write and all that.

I’ve hit this same problem with jira-ruby downloads. The gem handles auth automatically, but you’ve got to watch the response format. When you hit the attachment endpoint, you get raw file data back - not JSON. What fixed it for me: use the client’s request method directly instead of the basic get. Make sure you explicitly handle the content type since you’re dealing with binary data. Heads up - bigger files can blow up your memory if you’re not streaming the response. Also ran into attachment URLs that redirect, which killed downloads until I realized what was happening. The gem should follow redirects by default, but worth checking if your downloads keep failing.

Ran into this exact issue last month. You’ve got to build the full URL path manually for attachment downloads. The jira-ruby gem expects JSON responses, but attachments return binary data - that’s what’s breaking the parser. I fixed it by hitting the client’s HTTP layer directly: client.request(:get, "/rest/api/2/attachment/content/#{attachment_id}", headers: {'Accept' => '*/*'}). This skips the gem’s JSON parsing completely. One more thing - some Jira setups need extra permissions for downloading attachments even if you can see the metadata. Check your API user’s access if you’re getting auth errors.