Reputation: 1449
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
?
Upvotes: 2
Views: 4820
Reputation: 12331
[ProducesResponseType(typeof(FileStreamResult), (int)HttpStatusCode.OK)]
Upvotes: 4