could not create an instance of type microsoft.aspnetcore.http.iformfile

Viewed 22

I am fighting with this error for the last 3 days when I bind the value serImg on imgFile react app then it's showing this error

    [Route("PotService")]
    [HttpPost]
    public async Task<IActionResult> Post( [FromBody] ServiceInfo service)
    {

        MemoryStream stream = new MemoryStream(service.Data);
        IFormFile file = new FormFile(stream, 0, service.Data.Length, "test", "test");
        //service.serImg = file;

        ////string uploads1 = _hostingEnvironment.WebRootPath;

        //string uploads = Path.Combine( "Images");
       
        //    if (file.Length > 0)
        //    {
        //        string filePath = Path.Combine(uploads, service.serImg.FileName);
        //        using (Stream fileStream = new FileStream(filePath, FileMode.Create))
        //        {
        //             service.serImg.CopyToAsync(fileStream);
        //        }
        //    }
        bool result = _serManager.AddService(service);
        return Ok(true);

    }

It's used for a react app the code is

const onSubmit = async (data) => { data.CompanyInfoId = activeComId;

data.imgFile = data.serImg;
data.serType = data.serType.value;
data.serviceClose = data.serviceClose.value;
data.location = data.location.value;
console.log(data);
// console.log(data.serImg..value);
console.log(data.serviceClose.value);

const res = await fetch(serPost, {
  method: 'POST',
  body: JSON.stringify(data),
  headers: {
    'Content-type': 'application/JSON; carset=UTF-8',
  },
});
0 Answers
Related