check in display image using api now

This commit is contained in:
2025-09-10 11:15:56 +10:00
parent 6cea606cc2
commit ff45c461a5
23 changed files with 335 additions and 59 deletions
@@ -37,7 +37,67 @@ public class ImportPersonRepository
_config = config;
_httpContext = httpContext;
}
public async Task<string> GetImageAsBase64String(string imagePath)
{
try
{
// Read the image file into a byte array
//byte[] imageBytes = File.ReadAllBytes(imagePath);
byte[] imageBytes = await File.ReadAllBytesAsync(imagePath);
// Convert the byte array to a Base64 string
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
catch (FileNotFoundException)
{
Console.WriteLine($"Error: The file at '{imagePath}' was not found.");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
return null;
}
}
public async Task<ResultModel<string>> DownloadFile(DownloadFileCriteria criteria)
{
int statusCode = -1;
string result = "";
string error = "";
try
{
string imagePath = _config.GetValue<string>("AppSettings:ImageFolder");
string imageUrl = System.IO.Path.Combine(imagePath, criteria.FileName);
if (System.IO.File.Exists(imageUrl))
{
result = await this.GetImageAsBase64String(imageUrl);
statusCode = 1;
}
else
{
error = "error filename " + criteria.FileName + " can not find";
statusCode = -1;
}
}
catch (Exception ex)
{
statusCode = -1;
error = ex.Message;
}
return new ResultModel<string>
{
Data = result,
StatusCode = statusCode,
Message = error
};
}
public async Task<List<CodeDto<string>>> ImportPerson(MemoryStream fileStream, string sheetName)
{
Dictionary<string, ImportRelation> relationDic = new();