Hello, I referred to a script from the forum to send data via http post. So I used the same to add attachments to the jira issues using jira's rest api. I am able add images that are below 50kb where as above 50kb i see the image broken in jira's issue. Could anyone help what's going wrong with the code.
from base64 import b64encode
import os
import urllib2
jira_url = "https://domain-name/rest/api/2/issue/{issueID}/attachments"
username = "email.com"
api_token = "api_token"
auth =b64encode(username +":"+api_token)
file_path = system.file.openFile()
with open(file_path, 'rb') as file_stream:
file_data = file_stream.read()
Prepare the request
request = urllib2.Request(jira_url)
boundary = "----" + hex(hash(file_data))[2:]
request.add_header("Content-Type", "multipart/form-data; boundary={}".format(boundary))
Encode credentials for basic authentication
request.add_header("Authorization", "Basic {}".format(auth))
request.add_header("X-Atlassian-Token","no-check")
Build the request body
body = b''
body += b"--" + boundary + b"\r\n"
body += b"Content-Disposition: form-data; name="file"; filename="{}"\r\n".format(os.path.basename(file_path))
body += b"Content-Type: multipart/form-data;boundary:{}\r\n\r\n".format(boundary)
body += file_data
body += b"\r\n--" + boundary + b"--\r\n"
Set the request method and data
request.get_method = lambda: 'POST'
request.add_data(body)
Send the request
response = urllib2.urlopen(request)
print response.getcode()
print response.info()