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/DBControllers/MinIOchat.cs

37 lines
1.4 KiB
C#
Raw Normal View History

2022-11-02 17:39:39 +10:00
using Microsoft.AspNetCore.Mvc;
using Minio.DataModel;
using Minio;
using System.Security.Cryptography;
2022-11-25 22:40:17 +10:00
namespace NeDvachAPI.DBControllers
2022-11-02 17:39:39 +10:00
{
public class MinIOchat
{
2022-12-07 19:55:18 +10:00
public static async Task<JsonResult> PictureUpload(string fileroute, string filename, string bucket)
2022-11-02 17:39:39 +10:00
{
MinioClient DvachIo = new MinioClient()
.WithEndpoint(AuthInfo.MinIo.endpoint)
.WithCredentials(AuthInfo.MinIo.username, AuthInfo.MinIo.password)
//.WithSSL()
.Build();
Aes aesEncryption = Aes.Create();
aesEncryption.KeySize = 256;
aesEncryption.GenerateKey();
var ssec = new SSEC(aesEncryption.Key);
PutObjectArgs putObjectArgs = new PutObjectArgs()
2022-12-07 19:55:18 +10:00
.WithBucket(bucket)
2022-11-02 17:39:39 +10:00
.WithObject(filename)
.WithFileName(fileroute)
.WithContentType("image/png");
2022-11-25 22:40:17 +10:00
//.WithServerSideEncryption(ssec);
2022-11-02 17:39:39 +10:00
await DvachIo.PutObjectAsync(putObjectArgs);
2022-11-25 22:40:17 +10:00
GC.Collect();
GC.WaitForPendingFinalizers();
2022-11-03 15:13:58 +10:00
File.Delete(fileroute);
2022-11-02 17:39:39 +10:00
2022-11-03 15:13:58 +10:00
return new JsonResult("http://static.vdk2ch.ru:15555/thread-pics/" + filename);
2022-11-02 17:39:39 +10:00
}
}
}