using Microsoft.AspNetCore.Mvc; using NeDvachAPI.DBControllers; namespace NeDvachAPI.Controllers { [ApiController] [Route("[controller]")] public class UploadPic : ControllerBase { [HttpPost(Name = "UploadPicture")] public async Task ReceivePost([FromForm] IFormFile PostPicture) { string receivedFileName = PostPicture.FileName; string fName = Path.GetFileNameWithoutExtension(receivedFileName); string fExtention = Path.GetExtension(receivedFileName); string previevFileName = fName + 's' + fExtention; Console.WriteLine("Расширение файла: " + fExtention); if (ImageController.CheckExtention(fExtention)) //file type check { ///Local Buffer File Part string filePath; string previevPath; filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName; previevPath = Directory.GetCurrentDirectory() + "\\Buffer\\" + previevFileName; //creating original file buffer Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); PostPicture.CopyTo(picBuffer); picBuffer.Close(); //resizing ImageController.ResizeImage(filePath, previevPath, 300, 400); ///MinIo part await MinIOchat.PictureUpload(previevPath, receivedFileName, "thread-pics-small"); //upload thumbnail JsonResult picAdress = new(await MinIOchat.PictureUpload(filePath, receivedFileName, "thread-pics")); //upload fullsize Console.WriteLine("Загружен файл:" + "http://static.vdk2ch.ru:15555/thread-pics/" + receivedFileName); return picAdress; } else return new JsonResult("Неверный тип файла"); } } }