0

I am currently trying to receive and work with pdf/image-files in a net 6 web api.

I am testing my attempts through postman, loading a pdf-file into the body as a binary. I believe that, regardless of media type, I should be able to load the binary from the body into a stream and then go from there - but I can't get that to work.

Below are my two attempts of making the Postman-Test return anything that shows me I have successfully accessed the binary and turned it into a format I can work with.

Screenshot of my first approach tested via Postman, asking for a file

        [HttpPost]

        public async Task<dynamic> CreateDeal([FromForm] IFormFile file)
        {
            return file.Name;
        }

Screenshot of my second approach tested via Postman, telling me the media type is unsupported

        [HttpPost]

        public async Task<dynamic> CreateDeal([FromBody] Stream file)
        {
            return file.Length;
        }

Any help pointing me in the right direction would be greatly appreciated, would love to find some documentation I can read to clear up my (obvious) misunderstanding of some of the concepts.

  • Please post the code as text, not an image. – toyota Supra Sep 01 '22 at 00:44
  • @toyotaSupra how do I post the Postman Configuration as Text? Or do you mean it would be better to summarize the settings as text? – DerSeestern Sep 01 '22 at 03:33
  • Do [this](https://stackoverflow.com/a/39037889/1139830), but you have no text based parameters so your case is even simpler than that question. It's an IFormFile, so it would make sense to use the Form option in Postman. – mason Sep 01 '22 at 12:44

0 Answers0