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/MinIOchat.cs
RakVhalate e7d4292d82
Some checks failed
continuous-integration/drone/push Build is failing
Image upload function
2022-11-03 15:13:58 +10:00

40 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Minio.DataModel;
using Minio;
using System.Security.Cryptography;
namespace NeDvachAPI
{
public class MinIOchat
{
public static async Task<JsonResult> PictureUpload(string fileroute, string filename)
{
MinioClient DvachIo = new MinioClient()
.WithEndpoint(AuthInfo.MinIo.endpoint)
.WithCredentials(AuthInfo.MinIo.username, AuthInfo.MinIo.password)
//.WithSSL()
.Build();
//Console.WriteLine(filename);
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);
PutObjectArgs putObjectArgs = new PutObjectArgs()
.WithBucket(AuthInfo.MinIo.bucketName)
.WithObject(filename)
.WithFileName(fileroute)
.WithContentType("image/png");
//.WithServerSideEncryption(ssec);
//Console.WriteLine("Кидаю в minio...");
await DvachIo.PutObjectAsync(putObjectArgs);
//await Task.Delay(5000);
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
File.Delete(fileroute);
return new JsonResult("http://static.vdk2ch.ru:15555/thread-pics/" + filename);
}
}
}