marco.pms.api/Marco.Pms.Services/Controllers/WeatherForecastController.cs

54 lines
1.8 KiB
C#

using Marco.Pms.Model.Utilities;
using Marco.Pms.Services.Service;
using Microsoft.AspNetCore.Mvc;
namespace MarcoBMS.Services.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
private readonly S3UploadService _s3Service;
public WeatherForecastController(ILogger<WeatherForecastController> logger, S3UploadService s3Service)
{
_logger = logger;
_s3Service = s3Service;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
[HttpPost("upload-image")]
public async Task<IActionResult> SendToSThree([FromBody] FileUploadModel Image)
{
if (string.IsNullOrEmpty(Image.Base64Data))
return BadRequest("Base64 data is missing");
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, 1, "Forum");
//var objectKey = await _s3Service.UploadFileAsync(Image.FileName, Image.ContentType);
var preSignedUrl = _s3Service.GeneratePreSignedUrlAsync(objectKey);
return Ok(new
{
objectKey,
url = preSignedUrl
});
}
}
}