'Combine Json and file upload in a controller

I'm trying to send a form with Angular to a controller that contains json and a file.

[HttpPost("Save", Name = "SaveReportRequest")]
public ActionResult<ReportRequestBean> Save([Bind("deviceType,buildType,version,qGateDate,notes")]
            ReportRequestModel reportRequest, IFormFile file)
{
    // Validate reportRequest
    if (ModelState.IsValid == false)
    {
        return BadRequest("Invalid ModelState");
    }

    if (ValidateQGateDate(reportRequest.QGateDate) == false)
    {
        return BadRequest("QGateDate is outside of min or max.");
    }
}

But all I get is

[07:22:31 INF] Request finished HTTP/2 POST https://localhost:5001/api/ReportRequest/Save application/json 130 - 415 175 application/problem+json;+charset=utf-8 20.0784ms

How can I set the right Content-Type or how do I build it to make it work?



Solution 1:[1]

For me the easiest solution was to upload the file one by one and save them in a temp file. Then when I save the Form, I load the temp file and save it.

Solution 2:[2]

The best way is, send file inside your model

public class RequestModel
{
 ... (other properties)
 public IFormFile file { get; set; }
}

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Christian
Solution 2 Ali.Ahmadi