Skip to content

Commit

Permalink
Update jira.py add_attachment method (atlassian-api#1126)
Browse files Browse the repository at this point in the history
updated the code for working with the attachments
new method added -  add_attachment_object
  • Loading branch information
laralight authored Feb 23, 2023
1 parent 1379a2e commit fbe0cd3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions atlassian/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,12 +1197,24 @@ def add_attachment(self, issue_key, filename):
:param issue_key: str
:param filename: str, name, if file in current directory or full path to file
"""
with open(filename, "rb") as attachment:
return self.add_attachment_object (issue_key, attachment)

def add_attachment_object(self, issue_key, attachment):
"""
Add attachment to Issue
:param issue_key: str
:param attachment: IO object
"""
log.warning("Adding attachment...")
base_url = self.resource_url("issue")
url = "{base_url}/{issue_key}/attachments".format(base_url=base_url, issue_key=issue_key)
with open(filename, "rb") as attachment:
if attachment:
files = {"file": attachment}
return self.post(url, headers=self.no_check_headers, files=files)
else:
log.error("Empty attachment")
return None
return self.post(url, headers=self.no_check_headers, files=files)

def issue_exists(self, issue_key):
original_value = self.advanced_mode
Expand Down

0 comments on commit fbe0cd3

Please sign in to comment.