I\'m using jQuery ajax to upload file but want to add some parameters on webapi method, here is:
var data = new FormData();
data.append(\"file\", $(\"#file\"
Posting the FormData
object results in a request with content type multipart/form-data. You have to read the request content like so:
[HttpPost]
public async Task<string> Upload()
{
var provider = new MultipartFormDataStreamProvider("C:\\Somefolder");
await Request.Content.ReadAsMultipartAsync(provider);
var myParameter = provider.FormData.GetValues("myParameter").FirstOrDefault();
var count = provider.FileData.Count;
return count + " / " + myParameter;
}
BTW, this will save the file in the path specified, which is C:\\SomeFolder
and you can get the local file name using provider.FileData[0].LocalFileName;
Please take a look at MSDN code sample and Henrik's blog entry.