adding picture posting controller
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-11-02 17:39:39 +10:00
parent b2cf921b9a
commit f83b76b2de
10 changed files with 89 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using System.Net.Http.Headers;
using System.Text.Json;
using System.IO;
namespace NeDvachAPI.Controllers
{
@@ -8,12 +8,28 @@ namespace NeDvachAPI.Controllers
[Route("[controller]")]
public class UploadPic : ControllerBase
{
///Local Buffer File Part
string filePath;
[HttpPost(Name = "UploadPicture")]
public JsonResult ReceivePost([FromForm] IFormFile PostPicture)
public async Task<JsonResult> ReceivePost([FromForm] IFormFile PostPicture)
{
Console.Write("Принята картинка ");
Console.WriteLine(PostPicture.FileName);
return new JsonResult(PostPicture.FileName + " получен!");
var supportedTypes = new[] { "jpg", "png" };
string receivedFileName = PostPicture.FileName;
string fileExt = receivedFileName.Substring((receivedFileName.Length) - 3, 3);
Console.WriteLine("Тип файла: " + fileExt);
if (supportedTypes.Contains(fileExt)) //file type check
{
filePath = Directory.GetCurrentDirectory() + "\\Buffer\\" + receivedFileName;
Stream picBuffer = new FileStream(filePath, FileMode.Create, FileAccess.Write);
Console.WriteLine("Закидываю файл в " + filePath);
PostPicture.CopyTo(picBuffer);
picBuffer.Close();
return new JsonResult(await MinIOchat.PictureUpload(filePath, receivedFileName));
}
else return new JsonResult("Неверный тип файла");
}
}
}