Reading MVC4 WebApi Multipart Data

Viewed 5019

I'm sending multipart form-data to my WebApi controller. The content I'm interested in includes both an image and another non-image value. I can read the image no problem, but can't figure out how to read the username part (with andy as the value). It's not in the FormData property on the provider. How can I get it?

Multi-part Form Data

------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Filename"

image.jpg
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="username"

andy
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Filedata"; filename="image.jpg"
Content-Type: application/octet-stream


------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0
Content-Disposition: form-data; name="Upload"

Submit Query
------------ei4KM7KM7ae0GI3Ef1gL6ei4ae0ae0--

Controller Code

string root = System.Web.HttpContext.Current.Server.MapPath("~/App_Data");
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(root);

var task = request.Content.ReadAsMultipartAsync(provider).ContinueWith<HttpResponseMessage>(o =>
{ 
    ...
}
2 Answers
Related