Я не могу загружать вложения с помощью API fogbugz. Я следил за документацией fogbugz, но, может быть, я что-то не так. Произошла ошибка: Ex.Message = "Указанный ключ отсутствует в словаре".API Fogbugz - невозможно загрузить файл (реализация C#)
StackTrace = "в System.Collections.Generic.Dictionary 2.get_Item(TKey key) at UBR.Products.TimeTrakker.Client.Lib.FogBugz.FBApi.CallRESTAPIFiles(String sURL, Dictionary
2 rgArgs, словарь 2[] rgFiles) at UBR.Products.TimeTrakker.Client.Lib.FogBugz.FBApi.Cmd(String cmd, Dictionary
2 арг, словарь 2[] files) at Business.Services.Fogbugz.CreateBug(String title, String areaId, String summary, List
1 FILEDATA) в C: \ Dev \ RapidAppsFogbugz \ стволу \ Business \ Services \ Fogbugz.cs: строка 114"
public string CreateBug(string title, string areaId, string summary)
{
try
{
string bugIdResult;
//Build args from Bug object
var args = FillArgsDictionaryForCreatingBug(title, GetDefaultProjectID(), areaId, summary);
var fileArgs = GetAttachmentArgs(GetAttachmentList());
//args.Add("nFileCount", "1");
if (fileArgs != null) //WITH ATTACHMENTS
bugIdResult = GetBugId(_fogbugz.Cmd("new", args, fileArgs));
else //NO ATTACHMENTS
bugIdResult = GetBugId(_fogbugz.Cmd("new", args));
return bugIdResult;
}
catch (Exception ex)
{
throw new Exception(typeof(Fogbugz).ToString() + " : Method = CreateBug", ex);
}
}
private List<byte[]> GetAttachmentList()
{
List<byte[]> fileData = null;
if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
{
fileData = new List<byte[]>();
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
if (file.ContentLength > 0)
{
using (var binaryReader = new BinaryReader(file.InputStream))
{
fileData.Add(binaryReader.ReadBytes(file.ContentLength));
}
}
}
}
private Dictionary<string, string> FillArgsDictionaryForCreatingBug(string title, string projectId, string areaId, string summary)
{
var args = new Dictionary<string, string>
{
{"sTitle", title},
{"ixProject", projectId},
{"ixArea", areaId},
{"sEvent", summary}
};
return args;
}
private Dictionary<string,byte[]>[] GetAttachmentArgs(List<byte[]> fileData)
{
Dictionary<string, byte[]>[] result = null;
if (fileData != null)
{
var fileArgs = new List<Dictionary<string, byte[]>>();
for (int i = 0; i < fileData.Count; i++)
{
var dictionary = new Dictionary<string, byte[]> { { "File" + (i+1).ToString(), fileData[i] } };
fileArgs.Add(dictionary);
}
result = fileArgs.ToArray();
}
return result;
}