diff options
author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-11-06 20:40:07 +0100 |
---|---|---|
committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-11-06 20:40:07 +0100 |
commit | 8123a815bd0591ec0d5ecb9b874c6141d65da9c7 (patch) | |
tree | b7e38d3bfe42959d51ebc8fa33366d9197642849 | |
parent | 6e35afaee3e18d9c69e3ed90d0786f6b9d9dccb3 (diff) |
Dodat api za preuzimanje slika pomocu id-a.
-rw-r--r-- | Backend/Api/Api/Controllers/PostController.cs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Backend/Api/Api/Controllers/PostController.cs b/Backend/Api/Api/Controllers/PostController.cs index 31dbeef..62f77f1 100644 --- a/Backend/Api/Api/Controllers/PostController.cs +++ b/Backend/Api/Api/Controllers/PostController.cs @@ -13,9 +13,11 @@ namespace Api.Controllers public class PostController : ControllerBase { private readonly IPostService _postService; - public PostController(IPostService postService) + private readonly IFileService _fileService; + public PostController(IPostService postService, IFileService fileService) { _postService = postService; + _fileService = fileService; } [HttpPost("add")] @@ -52,5 +54,18 @@ namespace Api.Controllers return BadRequest(); } + [HttpGet("image/{id}")] + [Authorize(Roles = "User")] + public async Task<ActionResult> getImage(string id) + { + Models.File f =await _fileService.getById(id); + if (f == null || !System.IO.File.Exists(f.path)) + return BadRequest("Slika ne postoji"); + return File(System.IO.File.ReadAllBytes(f.path), "image/*", Path.GetFileName(f.path)); + + + } + + } } |