From 7722db052d3cad2774f738db3a9740f0ba8b7a38 Mon Sep 17 00:00:00 2001
From: AnandaTon <125332905+anandaAiemvong@users.noreply.github.com>
Date: Fri, 31 Mar 2023 14:58:53 +0700
Subject: [PATCH] =?UTF-8?q?=E0=B8=95=E0=B9=88=E0=B8=AD=20api=20upload=20fi?=
=?UTF-8?q?les?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Controllers/CandidateController.cs | 74 +++++++++++++++++++++++++++++-
1 file changed, 73 insertions(+), 1 deletion(-)
diff --git a/Controllers/CandidateController.cs b/Controllers/CandidateController.cs
index e8f9c6c..a1b7327 100644
--- a/Controllers/CandidateController.cs
+++ b/Controllers/CandidateController.cs
@@ -19,7 +19,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
#region " Fields "
private readonly CandidateService _candidateService;
-
+ private readonly MinIOService _minioService;
#endregion
#region " Constructor and Destructor "
@@ -712,6 +712,78 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
return Error(ex);
}
}
+ ///
+ /// ตัวอย่างในการเขียน api เพื่อทำการ upload file
+ ///
+ ///
+ /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ
+ /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง
+ /// ไม่ได้ Login เข้าระบบ
+ /// เมื่อเกิดข้อผิดพ ลาดในการทำงาน
+ // [HttpPost("upload"), DisableRequestSizeLimit]
+ // [ProducesResponseType(StatusCodes.Status200OK)]
+ // [ProducesResponseType(StatusCodes.Status400BadRequest)]
+ // [ProducesResponseType(StatusCodes.Status401Unauthorized)]
+ // [ProducesResponseType(StatusCodes.Status500InternalServerError)]
+ // [AllowAnonymous]
+ // public async Task> UploadFile()
+ // {
+ // try
+ // {
+ // if (Request.Form.Files == null || Request.Form.Files.Count == 0)
+ // {
+ // return Error(GlobalMessages.NoFileToUpload);
+ // }
+
+ // var file = Request.Form.Files[0];
+ // var doc = await _minioService.UploadFileAsync(file);
+
+ // return Success(doc);
+ // }
+ // catch (Exception ex)
+ // {
+ // return Error(ex);
+ // }
+ // }
+ [HttpGet("delete/{id:length(36)}")]
+ [AllowAnonymous]
+ public async Task> DeleteFile(Guid id)
+ {
+ try
+ {
+ await _minioService.DeleteFileAsync(id);
+
+ return Success();
+ }
+ catch (Exception ex)
+ {
+ return Error(ex);
+ }
+ }
+
+ [HttpGet("download/{id:length(36)}")]
+ [AllowAnonymous]
+ public async Task> DownloadFile(Guid id)
+ {
+ try
+ {
+ var file_data = await _minioService.DownloadFileAsync(id);
+
+ Response.Headers["Content-Disposition"] = $"inline; filename={file_data.FileName}";
+
+ var ret = new FileContentResult(file_data.FileContent, file_data.FileType)
+ {
+ FileDownloadName = file_data.FileName
+ };
+
+ return ret;
+ }
+ catch (Exception ex)
+ {
+ return Error(ex);
+ }
+ }
+
#endregion
}