Jira attachment download
How to download a attachment which is added to a specific ticket?
jira.get_attachement(jira_ticket_id) is showing the info of the attachment and the file url but can we download the file without any issue on the authentication?
Same or similar question: When getting the URL of an attachment. How can I download it due to authentication?
Hi, guys!
Unfortunately you can't download attachment without authentication. Because all attachments are protected by Jira.
But you can use requests library for it.
As an example:
from atlassian import Jira
import requests
# Connect to Jira
jira = Jira(
url='https://my-jira-server.org',
username='my_username',
password='my_password'
)
# Get attachment URL
attachment = jira.get_attachment(attachment_id)
attachment_url = attachment.get('content')
# Authentication using requests library
session = requests.Session()
session.auth = ('my_username', 'my_password')
session.post(attachment_url) # Or just https://my-jira-server.org
# Get the file
req = session.get(url=attachment_url) # Use allow_redirects=True attribute for redirects
# Get filename
name = str(attachment_url).split('/')[-1]
# Write the file
open(name, 'wb').write(req.content) # Use full path instead name if you need to write file to specific folder
# Close requests session
session.close()
May be we add this feature in future. 🤔
yea we can look to implement a function such as download_attachment(attachment_id, file_obj)
It will download the attachment data to be outputted into a file such as file_obj param received by the function.
In addition to returning the response received which can also be written into a file-object.
@gonchik do you give a green signal for it ?
@isaac-philip sure. Of course, please, send a PR
attachment = jira.get_attachment(attachment_id) Where can we get the attachment id? Is there any function that automatically take these id's based on the task ore issue?