I'm trying to post a file + some info to a WebApi I control. My problem is that I can't access the file on the WebAPI side, all other fields are OK.
Here is my Console Application code
using (HttpClient client = new HttpClient()) { using (MultipartFormDataContent content = new MultipartFormDataContent()) { string filename = "my_filename.png"; content.Add(new StringContent(DateTime.Now.ToString("yyyy-MM-dd")), "data"); byte[] file_bytes = webClient.DownloadData($"https://my_url/my_file.png"); content.Add( new ByteArrayContent(file_bytes), "file"); string requestUri = "http://localhost:51114/api/File"; HttpResponseMessage result = client.PostAsync(requestUri, content).Result; Console.WriteLine("Upload result {0}", result.StatusCode); } } Here is my WebAPI Code
[HttpPost] public void Post(IFormFile file, [FromForm] DateTime data) { if (file == null || file.Length == 0) { Response.StatusCode = StatusCodes.Status400BadRequest; return; } // Never reaches this point..... file is null } Any pointers on what I might be missing?