1

With Postman I'm trying to make a POST request to my api (see code below), to upload a file.

The request I make via Postman :

enter image description here

The code :

namespace Abbyytestrestapi.Controllers
{
    [Route("api/Abbyy")]
    [ApiController]
    public class AbbyyController : ControllerBase
    {
        [HttpGet("Templates")]
        public ActionResult  GetAvailableTemplates()
        {
            return Ok("test");
        }
        [HttpPost("ConvertFile/{templateKey}")]
        public ActionResult ConvertFile([FromBody] IFormFile pdfFile, string templateKey)
        {
            return Ok("hello");
        }
    }
}

Yet I get an error 400 bad request. I have no idea what I am doing wrong... Can you help me? :)

Thank you in advance

Cizzl
  • 324
  • 2
  • 11
JF Finet
  • 21
  • 3
  • 1
    Possible duplicate of [ASPNetCore - Uploading a file through REST](https://stackoverflow.com/questions/50223606/aspnetcore-uploading-a-file-through-rest) – Cizzl Jul 24 '19 at 08:24
  • That's it, thank you so much for the link! That solved my problem. Sorry for the duplicate, I did some research and didn't find that. – JF Finet Jul 24 '19 at 08:45

1 Answers1

0
[HttpPost("ConvertFile")]
    public ActionResult ConvertFile( [FromQuery] string templateKey , [FromBody] IFormFile pdfFile, string templateKey)
    {
        return Ok("hello");
    }

try to use it

  • Thanks for your answer. I deleted the third parameter from your code (I guess you forgot to get rid of it). I do that request now: "https://localhost:xxxxx/api/Abbyy/ConvertFile", with only the pdfFile key in the form-data, and I get error 400 again – JF Finet Jul 24 '19 at 08:17