2

I am trying to upload a file and also JSON body at the same time to a POST method as below

  public async Task<ResponseModel<PersonWriteResponse>> AddPerson([FromForm]IFormFile file, [FromForm]PersonPostRequest request)
        {
            var person = await _service.AddPerson(file,request);
            return ResponseModelHelper.BuildResponse(person, $"/production/person", "person");
        }

Both parameters are always null. In postman, I am specifying the content-type as "Multipart/form-data"
Is this the correct way of passing file and json data?

  • Alan-
Alan B
  • 2,219
  • 4
  • 32
  • 62
  • 1
    Possible duplicate of [Upload files and JSON in ASP.NET Core Web API](https://stackoverflow.com/questions/41367602/upload-files-and-json-in-asp-net-core-web-api) – RQDQ Aug 30 '18 at 15:06

1 Answers1

-1

I try to use model witch include IFormFile, and it's works

[HttpPost]
    [AllowAnonymous]
    public async Task<IActionResult> update([FromForm]MyFile model)
    {
        return Ok("Success!");
    }

    public class MyFile
    {
        public string Id { get; set; }        
        public IFormFile File { get; set; }
        // Other properties
    }

PostMan request here

You may set breakPoint at the return Ok("Success!"); line and saw what you get