Search code examples
.netangularswagger

.net/swagger resposne type Blob


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 ...


Solution

  • 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))]