生产缩略图
parent
8255857ec1
commit
91c3632040
|
|
@ -6,6 +6,7 @@ using Minio;
|
||||||
using Minio.DataModel;
|
using Minio.DataModel;
|
||||||
using Minio.DataModel.Args;
|
using Minio.DataModel.Args;
|
||||||
using Minio.Exceptions;
|
using Minio.Exceptions;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Infrastructure.CloudSdk.minio;
|
namespace Infrastructure.CloudSdk.minio;
|
||||||
|
|
||||||
|
|
@ -241,4 +242,45 @@ public class MinioService
|
||||||
var url = await _minioClient.PresignedGetObjectAsync(args);
|
var url = await _minioClient.PresignedGetObjectAsync(args);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task PutObjectAsync(string buketName,string tupianName,string objectName,MemoryStream memory) {
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(buketName))
|
||||||
|
{
|
||||||
|
buketName = _bucketName;
|
||||||
|
}
|
||||||
|
PutObjectArgs args = new PutObjectArgs();
|
||||||
|
args.WithBucket(buketName).WithObject(objectName).WithStreamData(memory).WithObjectSize(memory.Length).WithContentType("image/jpeg");
|
||||||
|
|
||||||
|
await _minioClient.PutObjectAsync(args);
|
||||||
|
|
||||||
|
}
|
||||||
|
public async Task<Stream> GetObjectAsStream(string bucketName, string objectName)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(bucketName))
|
||||||
|
{
|
||||||
|
bucketName = _bucketName;
|
||||||
|
}
|
||||||
|
var memoryStream = new MemoryStream();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _minioClient.GetObjectAsync(new GetObjectArgs()
|
||||||
|
.WithBucket(bucketName)
|
||||||
|
.WithObject(objectName)
|
||||||
|
.WithCallbackStream(stream =>
|
||||||
|
{
|
||||||
|
stream.CopyTo(memoryStream);
|
||||||
|
}));
|
||||||
|
|
||||||
|
memoryStream.Position = 0; // 重置流位置
|
||||||
|
return memoryStream;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error getting object: {e.Message}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -13,6 +13,12 @@ using StackExchange.Redis;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using SixLabors.ImageSharp;
|
||||||
|
using SixLabors.ImageSharp.Processing;
|
||||||
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||||
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
using Minio;
|
||||||
|
using Infrastructure.CloudSdk.minio;
|
||||||
|
|
||||||
namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
{
|
{
|
||||||
|
|
@ -27,13 +33,17 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
private readonly MqttClientManager _mqttClientManager;
|
private readonly MqttClientManager _mqttClientManager;
|
||||||
private readonly MqttMessageCenter _mqttCenter;
|
private readonly MqttMessageCenter _mqttCenter;
|
||||||
private readonly RedisCacheContext _cache;
|
private readonly RedisCacheContext _cache;
|
||||||
|
private readonly HttpClient _httpClient;
|
||||||
|
private readonly MinioService _minioService;
|
||||||
|
|
||||||
public AirportMaintenanceController(AirportMaintenanceApp app, MqttClientManager mqttClientManager, MqttMessageCenter mqttCenter, RedisCacheContext cache)
|
public AirportMaintenanceController(AirportMaintenanceApp app, MqttClientManager mqttClientManager, MqttMessageCenter mqttCenter, RedisCacheContext cache, HttpClient httpClient,MinioService minioService)
|
||||||
{
|
{
|
||||||
_app = app;
|
_app = app;
|
||||||
_mqttClientManager = mqttClientManager;
|
_mqttClientManager = mqttClientManager;
|
||||||
_mqttCenter = mqttCenter;
|
_mqttCenter = mqttCenter;
|
||||||
_cache = cache;
|
_cache = cache;
|
||||||
|
_httpClient = httpClient;
|
||||||
|
_minioService = minioService;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 机场注册 注册码生成
|
/// 机场注册 注册码生成
|
||||||
|
|
@ -745,6 +755,45 @@ namespace OpenAuth.WebApi.Controllers.ServiceControllers
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public async Task<Response<string>> getMiniPic()
|
||||||
|
{
|
||||||
|
var result = new Response<string>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// string presignedUrl = "http://175.27.168.120:6014/test/44fc8b4b-9448-4e79-a71d-536d094b8598/ad854032-d4b7-42dc-8ac0-d1faef0ebc1e/DJI_202507231000_002_ad854032-d4b7-42dc-8ac0-d1faef0ebc1e/DJI_20250723100110_0001_V.jpeg";
|
||||||
|
var imageStream = _minioService.GetObjectAsStream("test", "44fc8b4b-9448-4e79-a71d-536d094b8598/ad854032-d4b7-42dc-8ac0-d1faef0ebc1e/DJI_202507231000_002_ad854032-d4b7-42dc-8ac0-d1faef0ebc1e/DJI_20250723100110_0001_V.jpeg");
|
||||||
|
// var imageStream = await _httpClient.GetStreamAsync(presignedUrl);
|
||||||
|
|
||||||
|
using (var image = Image.Load(imageStream.Result))
|
||||||
|
{
|
||||||
|
var width = image.Width;
|
||||||
|
var height = image.Height;
|
||||||
|
var thumbnailSize = 100; // 缩略图大小,可以根据需要调整
|
||||||
|
var thumbnail = image.Clone(ctx => ctx.Resize(new ResizeOptions
|
||||||
|
{
|
||||||
|
Size = new Size(thumbnailSize, thumbnailSize),
|
||||||
|
Mode = ResizeMode.Crop // 根据需要选择裁剪或填充模式
|
||||||
|
}));
|
||||||
|
|
||||||
|
// 将缩略图保存到内存流中(为了上传)
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
thumbnail.SaveAsJpeg(memoryStream); // 可以根据需要选择不同的格式,如Png, Bmp等。
|
||||||
|
memoryStream.Position = 0; // 重置流的位置到开始处
|
||||||
|
|
||||||
|
// 上传缩略图到MinIO
|
||||||
|
await _minioService.PutObjectAsync("test" , "suolue_DJI_20250723100110_0001_V.jpeg", "abc/suolue_DJI_20250723100110_0001_V.jpeg", memoryStream); // 根据实际格式修改Content-Type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = ex.Message;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue