32 lines
829 B
C#
32 lines
829 B
C#
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using UserService.ImageUpload;
|
||
|
|
|
||
|
|
namespace UserApi.Controllers
|
||
|
|
{
|
||
|
|
[Route("api/[controller]")]
|
||
|
|
[ApiController]
|
||
|
|
public class ImageUploadController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly IImageUploadService _imageUploadService;
|
||
|
|
|
||
|
|
public ImageUploadController(IImageUploadService imageUploadService)
|
||
|
|
{
|
||
|
|
_imageUploadService = imageUploadService;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("upload")]
|
||
|
|
public async Task<IActionResult> UploadFile(IFormFile file)
|
||
|
|
{
|
||
|
|
var result = await _imageUploadService.UploadImageAsync(file);
|
||
|
|
|
||
|
|
if (!result.isOk)
|
||
|
|
{
|
||
|
|
return BadRequest(result.errorMessage);
|
||
|
|
}
|
||
|
|
|
||
|
|
return Ok(new { path = result.path });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|