Define Content-type Web API C#

Asked

Viewed 54 times

0

Good morning Guys, here’s the thing, I’m creating a Web API that should receive some parameters among them a binary format image with the content-type "octet-stream". The other parameters are sent at the call address, except the image according to the API documentation. I would like to know how I can receive this image in my controller. I have tried it as follows:

public class new_biometric_imageController : ApiController
{
    [HttpPost]
    [Route("api/new_biometric_image/{session}/{device_id}/{identifier_id}/{width}/{height}")]
    public IHttpActionResult new_biometric_image(string session, long device_id, long identifier_id, int width, int height, [FromBody] byte[] imagem)
    {
        try
        {



            return Ok("ok");

        }
        catch (Exception e)
        {
            var mensagem = "Não foram encontrados usuarios!";

            return Ok(mensagem);
        }

    }

}

However when performing tests with Postman, it receives all other parameters except the image sent, the option chosen in Postman is in body: Postman

Does anyone know how I can resolve this situation? I thank you in advance.

  • If the other parameters will come from the query, you can add the [FromQuery]... This route should not be in your atcion instead of the controller?

  • @Leandroangelo, thank you for answering, in case I use [Fromquery] in front of everyone in the action? I never used this method, I will give a search on. Regarding the [Route] was really wrong, already corrected.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.