问题描述
我试图在使用asp.net core 3.1实现网站时从jpg文件读取exif元数据,例如标题,描述和日期。以前,我是使用BitmapMetadata类(在asp.net核心中不可用)完成此操作的。我尝试了ExifLib和ExifLib.Standard NuGet软件包,但没有成功。
<form enctype="multipart/form-data" method="post">
<div class="form-group">
<label asp-for="FormFile"></label>
<input asp-for="FormFile" class="form-control-file" type="file" />
</div>
<input accept="image/jpeg" asp-page-handler="LoadInfo" class="btn btn-primary btn-sm" type="submit" value="Load Info" />
</form>
public IFormFile FormFile { get,set }
public string NewPhotoCaption { get,set }
public string NewPhotoDescription { get,set }
public DateTime NewPhotoDate { get,set }
public async Task<IActionResult> OnPostLoadInfoAsync()
{
if (ModelState.IsValid)
{
using (ExifReader reader = new ExifReader(FormFile.OpenReadStream()))
{
reader.GetTagValue(ExifTags.XPTitle,out string newPhotoCaption);
NewPhotoCaption = newPhotoCaption;
reader.GetTagValue(ExifTags.XPDescription,out string newPhotoDescription);
NewPhotoDescription = newPhotoDescription;
reader.GetTagValue(ExifTags.DateTime,out DateTime newPhotoDate);
NewPhotoDate = newPhotoDate;
}
}
return Page();
}
reader.GetTagValue方法的输出参数始终为null。我已经成功实例化了FormFile属性,因为我可以读取文件名,长度等(未显示代码)。
解决方法
我能够使用SixLabors.ImageSharp NuGet包从文件中读取jpeg元数据。
sudo pip3 install mysql-connector-python