I need to send file to WEB API using HttpClient and using the below code to achieve it. I couldn't figure out why am not revcieving any files in WEB API, but the request hits the APIcontroller.
Client Side Code
var fs = new FileStream(@"C:\SomLocation\ExcelFile.xlsx", FileMode.Open, FileAccess.Read);
MemoryStream ms = new MemoryStream();
fs.CopyTo(ms);
var client = new HttpClient();
client.BaseAddress = new Uri(GetAPIBaseAddress());
HttpContent content = new StreamContent(ms);
var data = new MultipartFormDataContent();
data.Add(content, "file1");
var response = client.PostAsync(GetImportAPIURL(), data).Result;
In API
System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
foreach(System.Web.HttpPostedFile file in hfc)
{
// do some processing;
}
Any help would be greatly appreciated.