1
我正在创建一个简单的winform应用程序,该应用程序可以使用所提供的API在Visual Studio Team Services敏捷工作流程中创建新的bug项目。 The API Documentation使用适用于Visual Studio Team Services的API添加附件
目前它可以创建一个新的bug,标题,标签和描述。
我想能够添加文件附件,但出于某种原因,这是行不通的。
代码来创建错误如下
private static void createInitailItemPostObject()
{
AddUpdateProp("/fields/System.Title", newTaskItem.Title);
AddUpdateProp("/fields/System.Tags", newTaskItem.Tags);
AddUpdateProp("/fields/System.Description", newTaskItem.Description);
AddUpdateProp("/fields/System.History", "Upload first file");
}
private static void AddUpdateProp(string field, string value)
{
DataObjectsProject.VSOJasonWorkItemPostData wiPostData = new DataObjectsProject.VSOJasonWorkItemPostData();
wiPostData.op = "add";
wiPostData.path = field;
wiPostData.value = value;
wiPostDataArr.Add(wiPostData);
}
JSON的调用与下面的代码
public static async void Post(string url, System.Net.Http.HttpContent wiPostDataContent, string returnType, JSONReturnCallBack callBack)
{
string responseString = String.Empty;
try
{
using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Basic",Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", username, password))));
using (System.Net.Http.HttpResponseMessage response = client.PostAsync(url, wiPostDataContent).Result)
{
response.EnsureSuccessStatusCode();
string ResponseContent = await response.Content.ReadAsStringAsync();
responseString = ResponseContent;
}
}
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
callBack(responseString,returnType);
}
要添加附件,完成我似乎无法得到它的转换下面的代码工作就像我目前的代码。
function readBlob() {
var files = document.getElementById('fileselect').files;
if (!files.length) {
alert('Please select a file!');
return;
}
var file = files[0];
var filename = file.name;
var reader = new FileReader();
reader.onloadend = function (evt) {
if (evt.target.readyState == FileReader.DONE) {
// Post file content to server
$.ajax({
url: "http://fabrikam.visualstudio.com/DefaultCollection/_apis/wit/attachments?filename=" + filename + "&api-version=1.0",
data: evt.target.result,
processData: false,
contentType: "application/json",
type: "POST"
});
}
};
reader.readAsArrayBuffer(file);
}
有没有其他人能做到这一点?
我使用的URL是下面的链接直接调用API
我一直在看那个小时。其他电话需要项目,但我猜测附件文件不会被存储在项目中。 接下来的阶段,你会将附件与任务,错误链接起来。 谢谢 –