atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Jira attachment download

Open kgrvamsi opened this issue 5 years ago • 7 comments

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?

kgrvamsi avatar Mar 04 '20 08:03 kgrvamsi

Same or similar question: When getting the URL of an attachment. How can I download it due to authentication?

mkjaxxo avatar Apr 01 '20 11:04 mkjaxxo

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()

SLRover avatar Apr 20 '20 23:04 SLRover

May be we add this feature in future. 🤔

SLRover avatar Apr 20 '20 23:04 SLRover

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.

isaac-philip avatar May 31 '20 17:05 isaac-philip

@gonchik do you give a green signal for it ?

isaac-philip avatar Jul 18 '21 13:07 isaac-philip

@isaac-philip sure. Of course, please, send a PR

gonchik avatar Feb 24 '23 19:02 gonchik

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?

Nachikethas1080 avatar Mar 02 '23 09:03 Nachikethas1080