Skip to content

Commit

Permalink
feat: store file name in the db
Browse files Browse the repository at this point in the history
Signed-off-by: SIGMazer <mazinasd7@gmail.com>
  • Loading branch information
SIGMazer committed Apr 21, 2024
1 parent 371ddb7 commit e7a1b2e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Controllers/ProjectTaskController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public async Task<IActionResult> UploadAttachment(int id, IFormFile file)
return BadRequest();
}
var fileContent = memoryStream.ToArray();
var fileName = Convert.ToBase64String(Encoding.UTF8.GetBytes(file.FileName));
var base64FileContent = Convert.ToBase64String(fileContent);
projectTask.Attachment = base64FileContent;
var fileContentWithFileName = fileName + "-" + base64FileContent;
projectTask.Attachment = fileContentWithFileName;
await _projectTaskRepository.UpdateAsync(projectTask);
await _projectTaskRepository.Save();
return Ok();
Expand All @@ -70,8 +72,12 @@ public async Task<IActionResult> GetAttachmentFile(int id){

try
{
var fileContent = Convert.FromBase64String(base64FileContent);
return File(fileContent, "application/octet-stream");
var fileName = base64FileContent.Split('-')[0];
var fileContent = base64FileContent.Split('-')[1];
var fileBytes = Convert.FromBase64String(fileContent);
var fileNameString = Convert.FromBase64String(fileName);
return File(fileBytes, "application/octet-stream", Encoding.UTF8.GetString(fileNameString));

}
catch (Exception e)
{
Expand Down

0 comments on commit e7a1b2e

Please sign in to comment.