This repository has been archived on 2023-06-30. You can view files and clone it, but cannot push or open issues or pull requests.
2chBackAPI/Controllers/PictureUpload.cs

36 lines
1.3 KiB
C#
Raw Normal View History

2022-11-02 01:45:42 +10:00
using Microsoft.AspNetCore.Mvc;
2022-11-02 17:39:39 +10:00
using System.IO;
2022-11-02 01:45:42 +10:00
namespace NeDvachAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class UploadPic : ControllerBase
{
2022-11-02 17:39:39 +10:00
///Local Buffer File Part
string filePath;
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);
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("Неверный тип файла");
2022-11-02 01:45:42 +10:00
}
}
}