Home > Back-end >  Azure Devops Upload Image
Azure Devops Upload Image

Time:10-01

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. Image on Devops enter image description here

CodePudding user response:

 ‘Paint cannot read this file. This is not a valid bitmap file, or its format is not currently supported'.

This error is not related to the code but the image which you are downloading must be corrupted so that might be the reason why paint unable to open this image.

You can try the below mentioned things :

1.Try to Open image on Different PC.

2.Open it in Another Photo Viewer Application.

3.Run Windows Troubleshooter.

4.Try to Open image on Different PC

CodePudding user response:

Please report this problem to Microsoft and raise a ticket on enter image description here

Download the file and open it:

enter image description here

  • Related