aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOgnjen Cirkovic <ciraboxkg@gmail.com>2022-11-06 20:40:07 +0100
committerOgnjen Cirkovic <ciraboxkg@gmail.com>2022-11-06 20:40:07 +0100
commit8123a815bd0591ec0d5ecb9b874c6141d65da9c7 (patch)
treeb7e38d3bfe42959d51ebc8fa33366d9197642849
parent6e35afaee3e18d9c69e3ed90d0786f6b9d9dccb3 (diff)
Dodat api za preuzimanje slika pomocu id-a.
-rw-r--r--Backend/Api/Api/Controllers/PostController.cs17
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));
+
+
+ }
+
+
}
}