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#
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 78,161 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 Answers by the question author, which helps users to know the answer solved the author's problem.