From 8123a815bd0591ec0d5ecb9b874c6141d65da9c7 Mon Sep 17 00:00:00 2001 From: Ognjen Cirkovic Date: Sun, 6 Nov 2022 20:40:07 +0100 Subject: Dodat api za preuzimanje slika pomocu id-a. --- Backend/Api/Api/Controllers/PostController.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Backend/Api') 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 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)); + + + } + + } } -- cgit v1.2.3