2022-11-02 01:45:42 +10:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-11-25 22:40:17 +10:00
|
|
|
|
using NeDvachAPI.DBControllers;
|
2022-11-02 17:39:39 +10:00
|
|
|
|
|
2022-11-02 01:45:42 +10:00
|
|
|
|
|
|
|
|
|
namespace NeDvachAPI.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("[controller]")]
|
|
|
|
|
public class UploadPic : ControllerBase
|
2022-11-25 22:40:17 +10:00
|
|
|
|
{
|
|
|
|
|
|
2022-11-02 17:39:39 +10:00
|
|
|
|
|
2022-11-02 01:45:42 +10:00
|
|
|
|
[HttpPost(Name = "UploadPicture")]
|
2022-11-02 17:39:39 +10:00
|
|
|
|
public async Task<JsonResult> ReceivePost([FromForm] IFormFile PostPicture)
|
2022-11-02 01:45:42 +10:00
|
|
|
|
{
|
2022-11-02 17:39:39 +10:00
|
|
|
|
var supportedTypes = new[] { "jpg", "png" };
|
|
|
|
|
string receivedFileName = PostPicture.FileName;
|
|
|
|
|
string fileExt = receivedFileName.Substring((receivedFileName.Length) - 3, 3);
|
2022-12-01 22:52:36 +10:00
|
|
|
|
if (supportedTypes.Contains(fileExt.ToLower())) //file type check
|
2022-11-02 17:39:39 +10:00
|
|
|
|
{
|
2022-11-25 22:40:17 +10:00
|
|
|
|
///Local Buffer File Part
|
|
|
|
|
string filePath;
|
2022-11-02 17:39:39 +10:00
|
|
|
|
filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName;
|
2022-11-03 15:13:58 +10:00
|
|
|
|
Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
|
2022-11-02 17:39:39 +10:00
|
|
|
|
PostPicture.CopyTo(picBuffer);
|
|
|
|
|
picBuffer.Close();
|
2022-11-03 15:13:58 +10:00
|
|
|
|
///MinIo part
|
|
|
|
|
JsonResult picAdress = new(await MinIOchat.PictureUpload(filePath, receivedFileName));
|
|
|
|
|
Console.WriteLine("Загружен файл:" + "http://static.vdk2ch.ru:15555/thread-pics/" + receivedFileName);
|
|
|
|
|
return picAdress;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 17:39:39 +10:00
|
|
|
|
else return new JsonResult("Неверный тип файла");
|
2022-11-02 01:45:42 +10:00
|
|
|
|
}
|
2022-11-03 15:13:58 +10:00
|
|
|
|
|
|
|
|
|
|
2022-11-02 01:45:42 +10:00
|
|
|
|
}
|
2022-11-03 15:13:58 +10:00
|
|
|
|
|
2022-11-02 01:45:42 +10:00
|
|
|
|
}
|