I am using Javascript (jQuery) to do a POST to Azure DevOps rest API to upload a simple image. But, I can't manage to get it working.
There isn't much detailed documentation at https://docs.microsoft.com/en-us/rest/api/azure/devops/wit/attachments/create?view=azure-devops-rest-5.0#upload_a_binary_file apart from understanding I we need to do a post to this endpoint.
POST https://dev.azure.com/fabrikam/_apis/wit/attachments?fileName=imageAsFileAttachment.png&api-version=5.0
Here is my current code. I can't figure out how do I send my image over to this endpoint? My image exists in a data-uri format.
var dataURI = $("img#target").attr("src");
var url = "https://xxx.visualstudio.com/_apis/wit/attachments?fileName=image.jpg&api-version=5.0";
jQuery.ajax ({
url: url,
type: "POST",
data: dataURI,
processData: false,
contentType: "application/octet-stream;charset=utf-8",
success: function(data){
console.log(data);
}
});
Help appreciated!