gpt4 book ai didi

TFS 附件大小 0 KB 通过 REST 调用

转载 作者:行者123 更新时间:2023-12-05 04:09:15 24 4
gpt4 key购买 nike

每当我尝试通过 REST 调用将附件附加到 TFS WorkItem 时,附件大小为 0KB。

首先,我使用以下代码在附件存储中上传附件。

https://{instance}/DefaultCollection/_apis/wit/attachments?api-version=1.0&filename="{fileName}"

我通过 rest 调用以字节数组形式发送数据。在此之后,我将该附件附加到工作项。

附加附件成功,但附件大小为零 KBTFS 有问题还是我做错了什么?

我使用 C# 语言进行编程,使用 REST Sharp 访问 VSTS API

 Dim restClient = New RestClient("Server URL")

restClient.Authenticator = New HttpBasicAuthenticator("UserId", "Password")

Dim request = New RestRequest("API_Name", Method.POST)

request.AlwaysMultipartFormData = False

request.AddParameter(String.Format("{0}; charset=utf-8", contentType), File.ReadAllBytes(filePath), ParameterType.RequestBody)

request.RequestFormat = DataFormat.Json

Dim response As IRestResponse = restClient.Execute(request)

Return response

我正在以字节为单位发送文件数据。

将附件附加到 WorkItem。

    Dim restClient = New RestClient(ACCESS_URL)
restClient.Authenticator = New HttpBasicAuthenticator(USER_NAME, PASSWORD)
Dim request = New
RestRequest("CollectionName}/_apis/wit/workitems/{WorkItem_ID}", Method.PATCH)

request.AddParameter("application/json-patch+json; charset=utf-8",
"post_Data", ParameterType.RequestBody)

request.RequestFormat = DataFormat.Json

Dim response As IRestResponse = restClient.Execute(request)
Return response

Post_Data 是一个json 字符串,它接受这种类型的数据

[{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "AttachedFile",
"url": "AttachementURI",

}]

最佳答案

您错过了 Post_Data 中的“属性”部分,请尝试以下操作:

[{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "AttachedFile",
"url": "AttachementURI",
"attributes": {
}
}]

关于TFS 附件大小 0 KB 通过 REST 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46329101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com