How to accept file in binary format in asp.net core web api

Andrii Shylin 221 Reputation points
2021-12-01T12:03:56.12+00:00

How to accept file in binary format in asp.net core web api controller and processed it. I have request see image below
154116-image.png

and i try to accept it in my controller but it doesn't work

        [HttpPost("catalist")]  
        public async Task<IActionResult> UploadFromCatalistAsync([FromBody] byte[] binaryFile, CancellationToken token)  
        {  
            //process binaryFile  
            return Ok();  
        }  
  

but I get error 415 Unsupported Media Type, could please help me what changes I need to make in my API to accept the file in this type?

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Bruce (SqlWork.com) 81,981 Reputation points Volunteer Moderator
    2021-12-01T15:45:16.373+00:00

    Don’t use a method parameter, instead use the body stream from the request.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.