使用ajax调用通过自定义小部件将附件添加到工作项

时间:2019-05-15 14:04:38

标签: azure-devops

如何使用ajax调用通过自定义窗口小部件向工作项添加附件。我了解了有关API调用的信息,但不了解如何实现,通过Ajax,我能够使用我的小部件创建工作项,但无法向其添加附件。在下面找到我的Ajax代码:

$(“#btnAttachment”)。click(function(){

    var restURL = "https://dev.azure.com/organizationName/{" + VSS.getWebContext().project.id + "}/_apis/wit/attachments?fileName='C:\Users\Administrator\Downloads\picturemessage_4hm34b3k.kot.png'&api-version=5.0";

    var myPatToken = "xyz";

    $.ajax({

        contentType: 'application/octet-stream',

        dataType: 'json',
        headers: {
            'Authorization': 'Basic ' + btoa("" + ":" + myPatToken)
        },
        success: function (data) {
            alert("Success");

        },
        error: function (data) {
            alert("Failure");
            console.log(JSON.stringify(data.responseText));
        },
        type: 'POST',
        url: restURL
    });
});

0 个答案:

没有答案