2020-12-12 14:18:31 +01:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Serwer.Infrastructure.Services;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Serwer.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ImageController : ControllerBase
|
|
|
|
|
{
|
2020-12-20 18:03:20 +01:00
|
|
|
|
private readonly IImageHandler _imageService;
|
|
|
|
|
public ImageController(IImageHandler imageService)
|
2020-12-12 14:18:31 +01:00
|
|
|
|
{
|
|
|
|
|
_imageService = imageService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("Process")]
|
2020-12-14 11:04:07 +01:00
|
|
|
|
public async Task<IActionResult> Process([FromForm]IFormFile image)
|
2020-12-12 14:18:31 +01:00
|
|
|
|
{
|
|
|
|
|
if(image == null)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
using (var memoryStream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
await image.CopyToAsync(memoryStream);
|
2020-12-12 18:11:56 +01:00
|
|
|
|
var response = await _imageService.Process(image.Name, image.ContentType, memoryStream.ToArray());
|
|
|
|
|
return Ok(response);
|
2020-12-12 14:18:31 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|