Skip to content

Commit fbe0cd3

Browse files
authored
Update jira.py add_attachment method (atlassian-api#1126)
updated the code for working with the attachments new method added - add_attachment_object
1 parent 1379a2e commit fbe0cd3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

atlassian/jira.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1197,12 +1197,24 @@ def add_attachment(self, issue_key, filename):
11971197
:param issue_key: str
11981198
:param filename: str, name, if file in current directory or full path to file
11991199
"""
1200+
with open(filename, "rb") as attachment:
1201+
return self.add_attachment_object (issue_key, attachment)
1202+
1203+
def add_attachment_object(self, issue_key, attachment):
1204+
"""
1205+
Add attachment to Issue
1206+
:param issue_key: str
1207+
:param attachment: IO object
1208+
"""
12001209
log.warning("Adding attachment...")
12011210
base_url = self.resource_url("issue")
12021211
url = "{base_url}/{issue_key}/attachments".format(base_url=base_url, issue_key=issue_key)
1203-
with open(filename, "rb") as attachment:
1212+
if attachment:
12041213
files = {"file": attachment}
1205-
return self.post(url, headers=self.no_check_headers, files=files)
1214+
else:
1215+
log.error("Empty attachment")
1216+
return None
1217+
return self.post(url, headers=self.no_check_headers, files=files)
12061218

12071219
def issue_exists(self, issue_key):
12081220
original_value = self.advanced_mode

0 commit comments

Comments
 (0)