check in display image using api now
This commit is contained in:
@@ -22,7 +22,7 @@ public class FileUploadController : ControllerBase
|
||||
_config = config;
|
||||
}
|
||||
|
||||
[HttpPost("UploadFile")]
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> UploadFile(IFormFile file)
|
||||
{
|
||||
List<CodeDto<string>> output = new ();
|
||||
@@ -36,7 +36,7 @@ public class FileUploadController : ControllerBase
|
||||
|
||||
// Define the upload directory
|
||||
// var uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "uploads");
|
||||
string importFolder = _config.GetValue<string>("ImportFolder");
|
||||
string importFolder = _config.GetValue<string>("AppSettings:ImportFolder");
|
||||
var uploadsFolder = Path.Combine(_hostingEnvironment.ContentRootPath, importFolder);
|
||||
if (!Directory.Exists(uploadsFolder))
|
||||
{
|
||||
@@ -72,4 +72,11 @@ public class FileUploadController : ControllerBase
|
||||
return StatusCode(500, $"Internal server error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("[action]")]
|
||||
public async Task<IActionResult> DownloadFile(DownloadFileCriteria criteria)
|
||||
{
|
||||
var rev = await _importPersonRepository.DownloadFile(criteria);
|
||||
return Ok(rev);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
#FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
#FROM mcr.microsoft.com/dotnet/aspnet:9::.0 AS base
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["FamilyTreeAPI/FamilyTreeAPI.csproj", "FamilyTreeAPI/"]
|
||||
COPY ["CommonAD/CommonAD.csproj", "CommonAD/"]
|
||||
RUN dotnet restore "./FamilyTreeAPI/FamilyTreeAPI.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/FamilyTreeAPI"
|
||||
@@ -18,9 +17,9 @@ FROM build AS publish
|
||||
RUN dotnet publish "./FamilyTreeAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
|
||||
WORKDIR /app
|
||||
ENV ASPNETCORE_HTTP_PORTS=80
|
||||
EXPOSE 80
|
||||
ENV ASPNETCORE_HTTP_PORTS=8080
|
||||
EXPOSE 8080
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "FamilyTreeAPI.dll"]
|
||||
@@ -10,6 +10,10 @@ public class FileContent
|
||||
public byte[] Content { get; set; }
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
public class DownloadFileCriteria
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
}
|
||||
public class UploadCriteria
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
The family Tree
|
||||
|
||||
Man and Woman
|
||||
|
||||
top level
|
||||
|
||||
1) TAM (M) has partner Jenny (F)
|
||||
|
||||
had child CAO (M)
|
||||
had Child Emmy (F)
|
||||
has Child Loan (F)
|
||||
|
||||
|
||||
2) CAO (M) has partner Lin (F)
|
||||
|
||||
has child Joe (M)
|
||||
has child TOM (M)
|
||||
|
||||
|
||||
3) Joe has partner Sophia (F)
|
||||
|
||||
has child Olivia (F)
|
||||
has child Mai (F)
|
||||
|
||||
|
||||
4) Henry has partner Loan (F)
|
||||
|
||||
has child Enya (F)
|
||||
has child Thanh (M)
|
||||
has child Chuong (M)
|
||||
|
||||
5) Henry has partner Brisa (F)
|
||||
has child Fern (F)
|
||||
has child Tim (M)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5015",
|
||||
"applicationUrl": "http://localhost:5016",
|
||||
"applicationUrl1": "http://192.168.8.188:5015"
|
||||
},
|
||||
"IIS Express": {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
"Kestrel_not_use": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
"Http": {
|
||||
"Url": "http://*:5015"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user