1. 缩略图提取并上传

2. 提取焦距、分辨率、大小等信息
3. 省对接相关部分修改
main
陈伟 1 month ago
parent 54d533ec75
commit e86dcb6c3c

@ -16,10 +16,10 @@ public class ExtData
public int pitch { get; set; }
public int roll { get; set; }
public DateTime? time { get; set; }
public double height { get; set; }
public double? height { get; set; }
public long imgWidth { get; set; }
public long imgHeight { get; set; }
public long imgOriginWidth { get; set; }
public long imgOriginHeight { get; set; }
public double psjj { get; set; }
public double? psjj { get; set; }
}

@ -1737,7 +1737,7 @@ namespace OpenAuth.App.ServiceApp
imgWidth = dimensions.width,
imgOriginHeight = dimensions.height,
imgOriginWidth = dimensions.width,
psjj = 24, // 等效焦距 todo 等效焦距如何取
psjj = lasaMediaFile.FocalLength,
time = lasaMediaFile.CreateTime,
height = lasaMediaFile.Height,
lon = lasaMediaFile.Lng,

@ -5,6 +5,9 @@ using Infrastructure.CloudSdk;
using Infrastructure.CloudSdk.minio;
using Infrastructure.CloudSdk.wayline;
using Infrastructure.Extensions;
using Irony.Parsing.Construction;
using MetadataExtractor;
using MetadataExtractor.Formats.Exif;
using Microsoft.Extensions.Logging;
using MQTTnet.Client;
using Newtonsoft.Json;
@ -250,7 +253,9 @@ public class ConfigSubscribe : IJob
FlightId = flightId,
TaskId = taskId,
ParentKey = "0",
Name = string.IsNullOrEmpty(executeTask.TaskName) ? timeStr : $"{executeTask.TaskName} {timeStr}",
Name = string.IsNullOrEmpty(executeTask.TaskName)
? timeStr
: $"{executeTask.TaskName} {timeStr}",
WorkspaceId = executeTask.WorkspaceId,
CreateTime = date,
};
@ -264,8 +269,111 @@ public class ConfigSubscribe : IJob
.Where(a => a.ObjectKey.Equals(objectKey)).SingleAsync();
if (mediaFile == null)
{
string objectKey1 = data.file.object_key.ToString();
string suoluokey = "minipic/" + data.file.name.ToString();
long? picSize = 0;
int width = 0, height = 0, focalLength = 0;
int offset = 0, length = 0;
var fileUrl ="http://" + _minioService.endPoint + "/" + _minioService._bucketName + "/" + objectKey;
using (var httpClient = new HttpClient())
{
// 目前读取64KB
// 添加Range请求头
httpClient.DefaultRequestHeaders.Range =
new System.Net.Http.Headers.RangeHeaderValue(0, 65535);
try
{
var response = httpClient
.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead).Result;
if (response.StatusCode == System.Net.HttpStatusCode.PartialContent)
{
//Focal Length 35: 24 mm
//Exif Image Width: 4032 pixels : Exif SubIFD
//Exif Image Height: 3024 pixels : Exif SubIFD
// 3.1 解析Content-Range头格式bytes start-end/total
var contentRange = response.Content.Headers.ContentRange;
if (contentRange != null)
{
picSize = contentRange.Length.Value;
Console.WriteLine(
$"获取范围:{contentRange.From}-{contentRange.To}/{contentRange.Length}");
}
// 成功获取部分内容
var y = response.Content.ReadAsByteArrayAsync().Result;
MemoryStream ms = new MemoryStream(y);
var directories = ImageMetadataReader.ReadMetadata(ms);
foreach (var directory in directories)
{
if (directory is ExifDirectoryBase)
{
if (directory.Name.Equals("Exif SubIFD"))
{
foreach (var tag in directory.Tags)
{
if (tag.Name.Equals("Exif Image Width"))
{
width = int.Parse(tag.Description.Replace("pixels", "")
.Trim());
}
if (tag.Name.Equals("Exif Image Height"))
{
height = int.Parse(tag.Description.Replace("pixels", "")
.Trim());
}
if (tag.Name.Equals("Focal Length 35"))
{
focalLength = int.Parse(tag.Description.Replace("mm", "")
.Trim());
}
}
}
//Console.WriteLine(directory.Name);
if (directory.Name.Equals("Exif Thumbnail"))
{
foreach (var tag in directory.Tags)
{
if (tag.Name.Equals("Thumbnail Offset"))
{
offset = int.Parse(tag.Description.Replace("bytes", "")
.Trim());
}
if (tag.Name.Equals("Thumbnail Length"))
{
length = int.Parse(tag.Description.Replace("bytes", "")
.Trim());
}
}
}
}
}
ms.Seek(offset + 6, SeekOrigin.Begin);
byte[] buffer = new byte[length];
int bytesRead = ms.Read(buffer, 0, length);
// 上传缩略图到MinIO
await _minioService.PutObjectAsync("", data.file.name.ToString(), suoluokey,
new MemoryStream(buffer));
}
else if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
// 服务器不支持Range请求返回完整内容
throw new InvalidOperationException("服务器不支持Range请求");
}
else
{
throw new HttpRequestException($"请求失败: {response.StatusCode}");
}
}
catch (Exception ex)
{
throw new Exception($"下载Range数据失败: {ex.Message}", ex);
}
}
/*string objectKey1 = data.file.object_key.ToString();
//缩略图处理
var imageStream = _minioService.GetObjectAsStream("", objectKey1);
var width = 0;
@ -293,7 +401,7 @@ public class ConfigSubscribe : IJob
await _minioService.PutObjectAsync("", data.file.name.ToString(), suoluokey,
memoryStream); // 根据实际格式修改Content-Type
}
}
}*/
var fileUpload = new LasaMediaFile()
{
@ -321,9 +429,10 @@ public class ConfigSubscribe : IJob
Width = width,
Height = height,
minipic = suoluokey,
//Size = size,
Size = picSize,
ShowOnMap = 1,
display = 1
display = 1,
FocalLength = focalLength
};
// todo 添加事务
await _sqlSugarClient.Insertable(fileUpload).ExecuteCommandAsync();

@ -108,9 +108,9 @@ public class LasaMediaFile
public string FileTags { get; set; }
public long Size { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public long? Size { get; set; }
public int? Width { get; set; }
public int? Height { get; set; }
public string Tid { get; set; }
public string Bid { get; set; }
@ -121,6 +121,8 @@ public class LasaMediaFile
public string minipic { get; set; }
public double? FocalLength { get; set; }
[SugarColumn(IsIgnore = true)] public List<LasaMediaFile> Children { get; set; }
[SugarColumn(IsIgnore = true)] public string CreateUserName { get; set; }

@ -9,6 +9,7 @@ using MetadataExtractor.Formats.Exif;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using OpenAuth.Repository.Domain;
namespace OpenAuth.WebApi.boot;
@ -423,6 +424,10 @@ public class TestAbc
[Test]
public void DownloadRange()
{
var minio = new MinioService();
long? picSize = 0;
int width = 0, height = 0, focalLength = 0;
int offset = 0, length = 0;
using (var httpClient = new HttpClient())
{
var total = 0L;
@ -432,7 +437,8 @@ public class TestAbc
{
var response = httpClient
.GetAsync(
"http://175.27.168.120:6013/test/640aea27-2dd3-4081-933c-fcef432fcec0/71924889-540d-4362-aeb1-9ee787a655a7/DJI_202508050906_002_71924889-540d-4362-aeb1-9ee787a655a7/DJI_20250805090809_0001_V.jpeg",
"http://" + minio.endPoint + "/" + minio._bucketName + "/" +
"/640aea27-2dd3-4081-933c-fcef432fcec0/71924889-540d-4362-aeb1-9ee787a655a7/DJI_202508050906_002_71924889-540d-4362-aeb1-9ee787a655a7/DJI_20250805090809_0001_V.jpeg",
HttpCompletionOption.ResponseHeadersRead).Result;
if (response.StatusCode == System.Net.HttpStatusCode.PartialContent)
@ -444,6 +450,7 @@ public class TestAbc
var contentRange = response.Content.Headers.ContentRange;
if (contentRange != null)
{
picSize = contentRange.Length;
Console.WriteLine($"获取范围:{contentRange.From}-{contentRange.To}/{contentRange.Length}");
}
@ -451,14 +458,37 @@ public class TestAbc
var y = response.Content.ReadAsByteArrayAsync().Result;
MemoryStream ms = new MemoryStream(y);
var directories = ImageMetadataReader.ReadMetadata(ms);
int offset = 0, length = 0;
foreach (var directory in directories)
{
if (directory is ExifDirectoryBase)
{
foreach (var directoryTag in directory.Tags)
{
Console.WriteLine($"{directoryTag.Name}: {directoryTag.Description} : { directoryTag.DirectoryName}");
Console.WriteLine(
$"{directoryTag.Name}: {directoryTag.Description} : {directoryTag.DirectoryName}");
}
if (directory.Name.Equals("Exif SubIFD"))
{
foreach (var tag in directory.Tags)
{
if (tag.Name.Equals("Exif Image Width"))
{
width = int.Parse(tag.Description.Replace("pixels", "")
.Trim());
}
if (tag.Name.Equals("Exif Image Height"))
{
height = int.Parse(tag.Description.Replace("pixels", "")
.Trim());
}
if (tag.Name.Equals("Focal Length 35"))
{
focalLength = int.Parse(tag.Description.Replace("mm", "")
.Trim());
}
}
}
//Console.WriteLine(directory.Name);
@ -480,13 +510,25 @@ public class TestAbc
}
}
var fileUpload = new LasaMediaFile()
{
Id = Guid.NewGuid().ToString(),
Width = width,
Height = height,
Size = picSize,
ShowOnMap = 1,
display = 1,
FocalLength = focalLength
};
Console.WriteLine("是否有错呢:" + JsonConvert.SerializeObject(fileUpload));
ms.Seek(offset + 6, SeekOrigin.Begin);
byte[] buffer = new byte[length];
int bytesRead = ms.Read(buffer, 0, length);
var x = IsValidImageFormat(buffer);
Console.WriteLine("是否为有效图片:" + x);
Console.WriteLine("读取的字节长度: " + bytesRead);
File.WriteAllBytes("f:/abcccc.jpeg", buffer);
File.WriteAllBytes("f:/abbbbbb.jpeg", buffer);
}
else if (response.StatusCode == System.Net.HttpStatusCode.OK)
{

Loading…
Cancel
Save