|
1 | | -using Microsoft.AspNetCore.Http; |
2 | | -using Microsoft.AspNetCore.Mvc; |
| 1 | +using Microsoft.AspNetCore.Mvc; |
3 | 2 | using ReturnFileWebApi.Interface; |
4 | 3 |
|
5 | | -namespace ReturnFileWebApi.Controllers |
| 4 | +namespace ReturnFileWebApi.Controllers; |
| 5 | + |
| 6 | +[Route("api/[controller]")] |
| 7 | +[ApiController] |
| 8 | +public class DownloadsController(IFileService fileService) : ControllerBase |
6 | 9 | { |
7 | | - [Route("api/[controller]")] |
8 | | - [ApiController] |
9 | | - public class DownloadsController : ControllerBase |
| 10 | + private readonly IFileService _fileService = fileService; |
| 11 | + private const string MimeType = "image/png"; |
| 12 | + private const string FileName = "CM-Logo.png"; |
| 13 | + |
| 14 | + [HttpGet("images-byte")] |
| 15 | + public IActionResult ReturnByteArray() |
| 16 | + { |
| 17 | + var image = _fileService.GetImageAsByteArray(); |
| 18 | + |
| 19 | + return File(image, MimeType, FileName); |
| 20 | + } |
| 21 | + |
| 22 | + [HttpGet("images-stream")] |
| 23 | + public IActionResult ReturnStream() |
10 | 24 | { |
11 | | - private readonly IFileService _fileService; |
12 | | - private const string MimeType = "image/png"; |
13 | | - private const string FileName = "CM-Logo.png"; |
14 | | - |
15 | | - public DownloadsController(IFileService fileService) |
16 | | - { |
17 | | - _fileService = fileService; |
18 | | - } |
19 | | - |
20 | | - [HttpGet("images-byte")] |
21 | | - public IActionResult ReturnByteArray() |
22 | | - { |
23 | | - var image = _fileService.GetImageAsByteArray(); |
24 | | - |
25 | | - return File(image, MimeType, FileName); |
26 | | - } |
27 | | - |
28 | | - [HttpGet("images-stream")] |
29 | | - public IActionResult ReturnStream() |
30 | | - { |
31 | | - var image = _fileService.GetImageAsStream(); |
32 | | - |
33 | | - return File(image, MimeType, FileName); |
34 | | - } |
| 25 | + var image = _fileService.GetImageAsStream(); |
| 26 | + |
| 27 | + return File(image, MimeType, FileName); |
| 28 | + } |
| 29 | + |
| 30 | + [HttpGet("images-stream-range")] |
| 31 | + public IActionResult ReturnStreamWithRanges() |
| 32 | + { |
| 33 | + var image = _fileService.GetImageAsStream(); |
| 34 | + |
| 35 | + return File(image, MimeType, FileName, enableRangeProcessing: true); |
35 | 36 | } |
36 | 37 | } |
0 commit comments