如何解决阅读jpeg元数据asp.net核心3.1
我试图在使用asp.net core 3.1实现网站时从jpg文件读取exif元数据,例如标题,描述和日期。以前,我是使用BitmapMetadata类(在asp.net核心中不可用)完成此操作的。我尝试了ExifLib和ExifLib.Standard NuGet软件包,但没有成功。
在Razor页面上,我有
<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>
在Razor页面的模型中,我有
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。