ต่อ api upload files
This commit is contained in:
parent
3ff5a4fa46
commit
7722db052d
1 changed files with 73 additions and 1 deletions
|
|
@ -19,7 +19,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
#region " Fields "
|
#region " Fields "
|
||||||
|
|
||||||
private readonly CandidateService _candidateService;
|
private readonly CandidateService _candidateService;
|
||||||
|
private readonly MinIOService _minioService;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region " Constructor and Destructor "
|
#region " Constructor and Destructor "
|
||||||
|
|
@ -712,6 +712,78 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
||||||
return Error(ex);
|
return Error(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// ตัวอย่างในการเขียน api เพื่อทำการ upload file
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
/// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
|
||||||
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||||
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||||
|
/// <response code="500">เมื่อเกิดข้อผิดพ ลาดในการทำงาน</response>
|
||||||
|
// [HttpPost("upload"), DisableRequestSizeLimit]
|
||||||
|
// [ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
// [ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
// [ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||||
|
// [ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||||
|
// [AllowAnonymous]
|
||||||
|
// public async Task<ActionResult<ResponseObject>> 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<ActionResult<ResponseObject>> 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<ActionResult<ResponseObject>> 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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue