private void ParseMultiPartItems(HttpClient client)
{
Files = new HttpFileCollection();
if (client.MultiPartItems == null)
return;
foreach (var item in client.MultiPartItems)
{
string contentType = null;
string name = null;
string fileName = null;
string header;
if (item.Headers.TryGetValue("Content-Disposition", out header))
{
string[] parts = header.Split(';');
for (int i = 0; i < parts.Length; i++)
{
string part = parts[i].Trim();
if (part.StartsWith("name="))
name = ParseContentDispositionItem(part.Substring(5));
else if (part.StartsWith("filename="))
fileName = ParseContentDispositionItem(part.Substring(9));
}
}
if (item.Headers.TryGetValue("Content-Type", out header))
contentType = header;
if (name == null)
{
Log.Info("Received multipart item without name");
continue;
}
if (item.Value != null)
{
Form[name] = item.Value;
}
else
{
Files.AddFile(name, new HttpPostedFile((int)item.Stream.Length, contentType, fileName, item.Stream));
}
}
}