1

I´m writing a Controllermethod in AspNet Core 5 that should return a file as stream.

[HttpGet]
[Route("/docs/{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetDocumentAsync([FromRoute][Required] Guid? id)
{
    var (stream, fileExtension) = await _dmsService.OpenDocumentAsync(id.Value, FileAccess.Read);
    return File(
        stream,
        contentType: "application/octet-stream",
        fileDownloadName: $"{id}{fileExtension}",
        enableRangeProcessing: false);
}

So far everything works but now I want to document the API.
Im using Swashbuckle.AspNetCore 6.1.4 to generate the OpenAPI description which than should be used to generate a client.

When I return some object it´s easy by using ActionResult<T> as return type.
But how can I tell Swashbuckle that the response is a stream?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
JakobFerdinand
  • 1,087
  • 7
  • 20
  • 1
    Look at here https://stackoverflow.com/questions/43844261/what-is-the-correct-way-to-download-a-file-via-the-nswag-code-generator-angular – Alexey Chuksin Jul 21 '21 at 10:21

1 Answers1

1
[ProducesResponseType(typeof(FileStreamResult), (int)HttpStatusCode.OK)]
Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63