0

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?

2
  • stackoverflow.com/questions/41367602/… Commented May 12, 2022 at 5:33
  • Maybe you can try define an IFormFile type property in model class, then pass data through FormData instead of passing it in json data.You can read this to know more. Commented May 12, 2022 at 8:57

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The best way is, send file inside your model

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

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.