I tried to test uploading an IFormFile through postman to web API and the error shows the IFormFile is a null value.
[HttpPost("upload")]
public async Task<string> Post(IFormFile photo)
{
try
{
// Full path to file in location
string fname = DoPhotoUpload(photo);
string filePath = Path.Combine(_env.WebRootPath, "photos/" + fname);
if (photo.Length > 0)
using (var stream = new FileStream(filePath, FileMode.Create))
await photo.CopyToAsync(stream);
//return Ok(new { count = 1, path = filePath });
return fname;
} catch (Exception ex)
{
return ex.Message;
}
The respsonse shows that my IFromFile is a null value but I am not able to find out where did I miss.