-
Notifications
You must be signed in to change notification settings - Fork 176
Cookbook
Geovanni Perez edited this page May 24, 2016
·
24 revisions
You can receive multipart request if you include this static method (from http://stackoverflow.com/questions/7460088/reading-file-input-from-a-multipart-form-data-post):
`` private static async Task ParseFiles(Stream data, string contentType, Action<string, Stream> fileProcessor) { var streamContent = new StreamContent(data); streamContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);
var provider = await streamContent.ReadAsMultipartAsync();
foreach (var httpContent in provider.Contents)
{
var fileName = httpContent.Headers.ContentDisposition.FileName;
if (string.IsNullOrWhiteSpace(fileName))
{
continue;
}
using (var fileContents = await httpContent.ReadAsStreamAsync())
{
fileProcessor(fileName.Replace("\"", ""), fileContents);
}
}
}
``
You need to include WebApi Client Nuget (https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Client)