I’m looking for an example on how to generate the request body when uploading an attachment to Azure DevOps Server. Looking at the documentation here, it notes the content for the body should be “[BINARY FILE CONTENT]”. The content of the body is coming from a URL (https://someURL/images/abc.png for example). How do I get from fetch(url) -> binary content to put in the POST request to create the attachment?
Advertisement
Answer
Found a solution that works. For reference here’s the code:
JavaScript
x
16
16
1
//Get the stream from the content URL
2
getStreamData(screenshot.src).then(function (streamData) {
3
4
//Get the blob data from the stream
5
streamData.blob().then(function (blob) {
6
7
//upload the attachment
8
uploadAttachment(blob, fileName).then(function (res) {
9
console.log("Attachment uploaded successfully: ", res);
10
11
//Update work item with attachment link
12
linkAttachmentToWorkitem(res.url, <workItemID>);
13
});
14
});
15
});
16
The key to all of this, for me anyway, was adding
JavaScript
1
2
1
processData: false
2
to the ajax settings, for the POST request, in the uploadAttachment function.