0

broken image

broken docs

iam trying to upload attachments to azuredevops but the files are broken ,not sure why

attachment_file = BytesIO(requests.get('http://127.0.0.1:8000'+attachment.attachment.url).content)
                           
files = {"file": (attachment.attachment_name,attachment_file)}

response_attachment =requests.post(attachment_url,files=files,headers={'Accept': 'application/json',"Content-Type": "application/octet-stream",},auth=HTTPBasicAuth(azure_username,azure_token))
SaiSakethGuduru
  • 2,218
  • 1
  • 5
  • 15
tamdo
  • 3
  • 1
  • 3
  • Does this answer your question? [Unable to upload attachment to Azure DevOps API correctly (0kb result)](https://stackoverflow.com/questions/53539831/unable-to-upload-attachment-to-azure-devops-api-correctly-0kb-result) – Joe Sep 02 '21 at 08:46
  • No the size is same as the original file – tamdo Sep 02 '21 at 08:58
  • i have added screen shots for files how they appears , i think its related to `io.bytes` – tamdo Sep 02 '21 at 09:00

1 Answers1

0

please try to convert that BytesIO object into readable format by using attachment_file.read() Try the below code it could helps you.

attachment_file = io.BytesIO(requests.get('http://127.0.0.1:8000'+attachment.attachment.url).content)
                           
files = {"file": (attachment.attachment_name,attachment_file.read())}

response_attachment =requests.post(attachment_url,files=files,headers={'Accept': 'application/json',"Content-Type": "application/octet-stream",},auth=HTTPBasicAuth(azure_username,azure_token))

Check here for more info

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15