parent
9bff4f2573
commit
ef6a67ae1f
|
|
@ -205,9 +205,12 @@ public class ConfigSubscribe : IJob
|
|||
switch (method)
|
||||
{
|
||||
case "file_upload_callback":
|
||||
// todo 非图片文件添加文件大小
|
||||
// todo 添加媒体文件类型
|
||||
//
|
||||
// 文件上传
|
||||
Console.WriteLine("进入文件上传处理");
|
||||
Console.WriteLine($"文件上传处理:{message}");
|
||||
_logger.LogInformation("进入文件上传处理");
|
||||
_logger.LogInformation($"文件上传处理:{message}");
|
||||
int flightType = data.flight_task.flight_type;
|
||||
string flightId = data.file.ext.flight_id;
|
||||
var taskAssign = _manageApp.GetTaskAssignByFlightId(flightId);
|
||||
|
|
@ -268,40 +271,65 @@ public class ConfigSubscribe : IJob
|
|||
.Where(a => a.ObjectKey.Equals(objectKey)).SingleAsync();
|
||||
if (mediaFile == null)
|
||||
{
|
||||
var type = 0;
|
||||
var preSize = 512;
|
||||
// todo 判断是不是图片
|
||||
if (objectKey.EndsWith(".jpeg")) // todo 是否有其它类型的图片,待确定
|
||||
{
|
||||
preSize = 65535;
|
||||
var fileName = Path.GetFileNameWithoutExtension(objectKey);
|
||||
var fileNameParts = fileName.Split("_");
|
||||
var suffix = fileNameParts[^1];
|
||||
type = suffix switch
|
||||
{
|
||||
// 0 未知 1 可见光 2 红外 3 变焦 4.广角 5 视频
|
||||
"V" => 1,
|
||||
"T" => 2,
|
||||
"Z" => 3, // 变焦
|
||||
"W" => 4, // 广角
|
||||
_ => type
|
||||
};
|
||||
}
|
||||
else if (objectKey.EndsWith(".mp4"))
|
||||
{
|
||||
type = 5;
|
||||
}
|
||||
|
||||
string suoluokey = "";
|
||||
long? picSize = 0;
|
||||
long? fileSize = 0;
|
||||
int width = 0, height = 0, focalLength = 0;
|
||||
int offset = 0, length = 0;
|
||||
string model = "";
|
||||
if (objectKey.ToLower().EndsWith("jpeg"))
|
||||
{
|
||||
var fileUrl = "http://" + _minioService.endPoint + "/" + _minioService._bucketName +
|
||||
"/" + objectKey;
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
suoluokey = "minipic/" + data.file.name.ToString();
|
||||
// 目前读取64KB
|
||||
// 添加Range请求头
|
||||
httpClient.DefaultRequestHeaders.Range =
|
||||
new RangeHeaderValue(0, 65535);
|
||||
try
|
||||
{
|
||||
var response = httpClient
|
||||
.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead).Result;
|
||||
if (response.StatusCode == 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 fileUrl = "http://" + _minioService.endPoint + "/" + _minioService._bucketName +
|
||||
"/" + objectKey;
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
suoluokey = "minipic/" + data.file.name.ToString();
|
||||
// 目前读取64KB
|
||||
// 添加Range请求头
|
||||
httpClient.DefaultRequestHeaders.Range =
|
||||
new RangeHeaderValue(0, preSize);
|
||||
try
|
||||
{
|
||||
var response = httpClient
|
||||
.GetAsync(fileUrl, HttpCompletionOption.ResponseHeadersRead).Result;
|
||||
if (response.StatusCode == 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)
|
||||
{
|
||||
fileSize = contentRange.Length.Value;
|
||||
Console.WriteLine(
|
||||
$"获取范围:{contentRange.From}-{contentRange.To}/{contentRange.Length}");
|
||||
}
|
||||
|
||||
if (objectKey.ToLower().EndsWith("jpeg"))
|
||||
{
|
||||
// 成功获取部分内容
|
||||
var y = response.Content.ReadAsByteArrayAsync().Result;
|
||||
MemoryStream ms = new MemoryStream(y);
|
||||
|
|
@ -384,10 +412,10 @@ public class ConfigSubscribe : IJob
|
|||
throw new HttpRequestException($"请求失败: {response.StatusCode}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"下载Range数据失败: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"下载Range数据失败: {ex.Message}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -421,11 +449,12 @@ public class ConfigSubscribe : IJob
|
|||
Width = width,
|
||||
Height = height,
|
||||
minipic = suoluokey,
|
||||
Size = picSize,
|
||||
Size = fileSize,
|
||||
ShowOnMap = 1,
|
||||
display = 1,
|
||||
FocalLength = focalLength,
|
||||
PayloadModelName = model
|
||||
PayloadModelName = model,
|
||||
Type = type
|
||||
};
|
||||
// todo 添加事务
|
||||
await _sqlSugarClient.Insertable(fileUpload).ExecuteCommandAsync();
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ public class LasaMediaFile
|
|||
public double? FocalLength { get; set; }
|
||||
|
||||
public string PayloadModelName { get; set; }
|
||||
public int? Type { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)] public List<LasaMediaFile> Children { get; set; }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue