使用 JavaScript 应用程序中的 Rest API 将附件上传到 Azure DevOps Server

发布于 2025-01-09 12:17:12 字数 368 浏览 0 评论 0原文

我正在寻找有关如何在将附件上传到 Azure DevOps Server 时生成请求正文的示例。查看文档 这里,它指出正文的内容应该是“[BINARY FILE CONTENT]”。正文的内容来自 URL(例如 https://someURL/images/abc.png)。我如何从 fetch(url) -> 获取要放入 POST 请求中以创建附件的二进制内容?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2025-01-16 12:17:12

找到了一个有效的解决方案。供参考的代码如下:

        //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

在 uploadAttachment 函数中为 POST 请求添加 ajax 设置。

Found a solution that works. For reference here's the code:

        //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>);
                });
            });
        });

The key to all of this, for me anyway, was adding

processData: false

to the ajax settings, for the POST request, in the uploadAttachment function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文