Implemented functionality to whitelist file extensions during upload to S3 #26

Merged
admin merged 2 commits from Ashutosh_Task#106_Upload_Whitelist_Only into Feature_Forum 2025-04-26 10:52:30 +00:00
3 changed files with 20 additions and 21 deletions
Showing only changes of commit 882dc50671 - Show all commits

View File

@ -513,7 +513,7 @@ namespace MarcoBMS.Services.Controllers
if (string.IsNullOrEmpty(Image.Base64Data))
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Base64 data is missing", 400));
objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, TenantId, "Attendance");
objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, TenantId, "attendance");
preSignedUrl = _s3Service.GeneratePreSignedUrlAsync(objectKey);
document = new Document

View File

@ -69,7 +69,7 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Base64 data is missing", 400));
}
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "Forum");
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "forum");
Document document = attachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, createTicketDto.CreatedAt, tenantId);
_context.Documents.Add(document);
@ -185,7 +185,7 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Base64 data is missing", 400));
}
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "Forum");
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "forum");
Document document = attachmentDto.ToDocumentFromUpdateAttachmentDto(objectKey, objectKey, updateTicketDto.CreatedAt, tenantId);
_context.Documents.Add(document);
@ -343,7 +343,7 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Base64 data is missing", 400));
}
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "Forum");
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "forum");
Document document = attachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, addCommentDto.SentAt, tenantId);
_context.Documents.Add(document);
@ -418,7 +418,7 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Base64 data is missing", 400));
}
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "Forum");
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, tenantId, "forum");
Document document = attachmentDto.ToDocumentFromUpdateAttachmentDto(objectKey, objectKey, existingComment.SentAt, tenantId);
_context.Documents.Add(document);
@ -500,7 +500,7 @@ namespace Marco.Pms.Services.Controllers
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Base64 data is missing", 400));
}
var objectKey = await _s3Service.UploadFileAsync(forumAttachmentDto.Base64Data, tenantId, "Forum");
var objectKey = await _s3Service.UploadFileAsync(forumAttachmentDto.Base64Data, tenantId, "forum");
Document document = forumAttachmentDto.ToDocumentFromForumAttachmentDto(objectKey, objectKey, forumAttachmentDto.SentAt, tenantId);
_context.Documents.Add(document);

View File

@ -1,4 +1,3 @@
using Marco.Pms.Model.Utilities;
using Marco.Pms.Services.Service;
using Microsoft.AspNetCore.Mvc;
@ -33,22 +32,22 @@ namespace MarcoBMS.Services.Controllers
})
.ToArray();
}
[HttpPost("upload-image")]
public async Task<IActionResult> SendToSThree([FromBody] FileUploadModel Image)
{
if (string.IsNullOrEmpty(Image.Base64Data))
return BadRequest("Base64 data is missing");
var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, 1, "Forum");
//var objectKey = await _s3Service.UploadFileAsync(Image.FileName, Image.ContentType);
var preSignedUrl = _s3Service.GeneratePreSignedUrlAsync(objectKey);
//[HttpPost("upload-image")]
//public async Task<IActionResult> SendToSThree([FromBody] FileUploadModel Image)
//{
// if (string.IsNullOrEmpty(Image.Base64Data))
// return BadRequest("Base64 data is missing");
// var objectKey = await _s3Service.UploadFileAsync(Image.Base64Data, 1, "Forum");
// //var objectKey = await _s3Service.UploadFileAsync(Image.FileName, Image.ContentType);
// var preSignedUrl = _s3Service.GeneratePreSignedUrlAsync(objectKey);
return Ok(new
{
objectKey,
url = preSignedUrl
});
// return Ok(new
// {
// objectKey,
// url = preSignedUrl
// });
}
//}
}
}