fixed download if no image return empty

This commit is contained in:
2026-09-20 15:30:22 +10:00
parent 3d83e95613
commit 5292b99af6
5 changed files with 60 additions and 14 deletions
@@ -93,8 +93,42 @@ namespace FamilyTreeAPI.Repository
Message = error
};
}
public async Task<ResultModel<FileContent>> DownloadPersonPhotoById(int Id)
{
public async Task<ResultModel<FileContent>> DownloadPersonPhoto(int personId, int photoType, string filename)
int statusCode = -1;
string error = "";
string extension = "";
PersonPhoto? model = null;
FileContent fileContent = new();
try {
model = await _context.PersonPhotos.FindAsync(Id);
if (model != null)
{
extension = Helpers.GetFileExtension(model.Photo);
fileContent.ContentType = Helpers.GetFileContent(extension);
fileContent.Content = (byte[])model.ImagePhoto;
fileContent.FileName = model.Photo;
statusCode = 1;
}
}
catch (Exception e)
{
error = e.ToString();
statusCode = -1;
}
return new ResultModel<FileContent>()
{
Data = fileContent,
StatusCode = statusCode,
Message = error
};
}
public async Task<ResultModel<FileContent>> DownloadPersonPhotoPerson(int personId, int photoType, string filename)
{
int statusCode = -1;
@@ -756,12 +756,15 @@ public partial class PersonRepository : IPerson
// DownloadFileCriteria criteria = new() { FileName = filename };
var resultModel = await _personPhoto.DownloadPersonPhoto(personId, photoType , filename);
//if (resultModel.Data.Content)
string base64String = Convert.ToBase64String(resultModel.Data.Content);
var resultModel = await _personPhoto.DownloadPersonPhotoPerson(personId, photoType , filename);
if (resultModel.StatusCode > 0)
{
if (!string.IsNullOrEmpty(base64String))
result = "data:image/png;base64," + base64String;
string base64String = Convert.ToBase64String(resultModel.Data.Content);
if (!string.IsNullOrEmpty(base64String))
result = "data:image/png;base64," + base64String;
}
return result;
}