使用 Rest API 从 JavaScript 应用程序将附件上传到 Azure DevOps Server
Uploading an attachment to Azure DevOps Server using Rest API from a JavaScript application
我正在寻找有关在将附件上传到 Azure DevOps Server 时如何生成请求正文的示例。查看文档 here,它指出正文的内容应该是“[BINARY FILE CONTENT]”。正文的内容来自 URL(例如 https:///someURL/images/abc.png)。我如何从 fetch(url) -> 二进制内容中获取以放入 POST 请求以创建附件?
找到了有效的解决方案。这里的代码供参考:
//Get the stream from the content URL
getStreamData(screenshot.src).then(function (streamData) {
//Get the blob data from the stream
streamData.blob().then(function (blob) {
//upload the attachment
uploadAttachment(blob, fileName).then(function (res) {
console.log("Attachment uploaded successfully: ", res);
//Update work item with attachment link
linkAttachmentToWorkitem(res.url, <workItemID>);
});
});
});
对我来说,所有这一切的关键是添加
processData: false
到 ajax 设置,对于 POST 请求,在 uploadAttachment 函数中。
我正在寻找有关在将附件上传到 Azure DevOps Server 时如何生成请求正文的示例。查看文档 here,它指出正文的内容应该是“[BINARY FILE CONTENT]”。正文的内容来自 URL(例如 https:///someURL/images/abc.png)。我如何从 fetch(url) -> 二进制内容中获取以放入 POST 请求以创建附件?
找到了有效的解决方案。这里的代码供参考:
//Get the stream from the content URL
getStreamData(screenshot.src).then(function (streamData) {
//Get the blob data from the stream
streamData.blob().then(function (blob) {
//upload the attachment
uploadAttachment(blob, fileName).then(function (res) {
console.log("Attachment uploaded successfully: ", res);
//Update work item with attachment link
linkAttachmentToWorkitem(res.url, <workItemID>);
});
});
});
对我来说,所有这一切的关键是添加
processData: false
到 ajax 设置,对于 POST 请求,在 uploadAttachment 函数中。