แก้บันทึกพ้นราชการ (ยังไม่เสร็จ)
This commit is contained in:
parent
e55c0f746b
commit
2e7abdb60a
13 changed files with 12478 additions and 189 deletions
|
|
@ -18,6 +18,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
private readonly ApplicationDBContext _context;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly AmazonS3Client _s3Client;
|
||||
private readonly IWebHostEnvironment _hostingEnvironment;
|
||||
private string _bucketName = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
|
@ -25,10 +26,12 @@ namespace BMA.EHR.Application.Repositories
|
|||
#region " Constructors "
|
||||
|
||||
public MinIOService(ApplicationDBContext context,
|
||||
IConfiguration configuration)
|
||||
IConfiguration configuration,
|
||||
IWebHostEnvironment hostingEnvironment)
|
||||
{
|
||||
_context = context;
|
||||
_configuration = configuration;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
|
||||
var config = new AmazonS3Config
|
||||
{
|
||||
|
|
@ -252,5 +255,84 @@ namespace BMA.EHR.Application.Repositories
|
|||
return "EMPLOYEE_TEMP";
|
||||
return "EMPLOYEE";
|
||||
}
|
||||
|
||||
public async Task UploadFileAsyncTemp(string fileName, string subFolder)
|
||||
{
|
||||
try
|
||||
{
|
||||
var fileContents = File.ReadAllBytes(fileName);
|
||||
System.IO.MemoryStream filestream = new System.IO.MemoryStream(fileContents);
|
||||
//var fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName);
|
||||
var fileExt = Path.GetExtension(fileName);
|
||||
// var fileType = MimeTypeMap.GetMimeType(fileExt);
|
||||
var file_name = Path.GetFileName(fileName);
|
||||
|
||||
var request = new PutObjectRequest
|
||||
{
|
||||
BucketName = $"{_bucketName}{subFolder}",
|
||||
Key = file_name,
|
||||
InputStream = filestream,
|
||||
// ContentType = fileType,
|
||||
CannedACL = S3CannedACL.PublicRead
|
||||
};
|
||||
|
||||
await _s3Client.PutObjectAsync(request);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GenerateJsonFile(string json, string path, string fileName)
|
||||
{
|
||||
var tmpFile = "";
|
||||
try
|
||||
{
|
||||
var tmpDir = Path.Combine(_hostingEnvironment.ContentRootPath, "tmp");
|
||||
if (!Directory.Exists(tmpDir))
|
||||
Directory.CreateDirectory(tmpDir);
|
||||
|
||||
tmpFile = Path.Combine(tmpDir, fileName);
|
||||
SaveToJsonFile(tmpFile, json);
|
||||
|
||||
await UploadFileAsyncTemp(tmpFile, path);
|
||||
|
||||
return "EMPLOYEE";
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tmpFile != "")
|
||||
{
|
||||
if (System.IO.File.Exists(tmpFile))
|
||||
System.IO.File.Delete(tmpFile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveToJsonFile(string fileName, string data)
|
||||
{
|
||||
TextWriter writer = null;
|
||||
try
|
||||
{
|
||||
writer = new StreamWriter(fileName);
|
||||
writer.Write(data);
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (writer != null)
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue