1

Is it possible to set in the c# controller response type Blob ? I automatically generate a client from swagger, and I want to return a blob to preview the pdf.

Angular

var f = new Blob([response], type: 'application/pdf'});
var url = URL.createObjectURL(f);
window.open(url);

c#

[ProducesResponseType(typeof(???), 200)]
[Procudes("application/pdf")

locally it works but on the server I have an error: http failure during parsing for ...

VMG
  • 123
  • 13
  • Maybe this could help you: https://stackoverflow.com/questions/9541351/returning-binary-file-from-controller-in-asp-net-web-api – Zsolt Balint Mar 10 '23 at 13:45

1 Answers1

1

I have got something similar to facilitate file downloads through the API. I use the ControllerBase.File() helper which returns a FileStreamResult.

As such I use Type = typeof(FileResult).

[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FileResult))]
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(BadRequestResult))]
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(NotFoundResult))]
phuzi
  • 12,078
  • 3
  • 26
  • 50