I am importing a lot of data into Azure Devops using python. I have all the pieces working. I can upload images, my issue is when I download the image from the Devops website it is not a valid file. I will share my image upload code.
def convertAttachmentToJsonBinary(attachmentPath):
file = open(attachmentPath, 'rb')
file_data = file.read()
encoded_data = base64.b64encode(file_data)
decoded_data = encoded_data.decode()
data = "[" + decoded_data + "]"
return data
def patchWorkItemWithAttachment(case_id, att_id, att_url):
json_template = open("attachment.json", "r")
json_data = json.load(json_template)
json_data[0]['value']['url'] = att_url
json_data[0]['value']['attributes']['comment'] = "Adding attachment"
response = requests.patch(patch_workitem_url.replace("{id}", case_id), json=json_data, headers=headers)
print(response.json())
While I am uploading a new case, I create the case, add attachments, then patch the newly created case with the new attachment. Again all of this work. I can see the attachment in my case online, however when I download it the file is invalid.
