Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {


group = "com.icc.qasker"
version = "1.6.0"
version = "1.6.1"

subprojects {
apply plugin: 'java'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ public interface S3ValidateService {
void checkCloudFrontUrlWithThrowing(String url);


void validateFileWithThrowing(String fileName, String contentType);
void validateFileWithThrowing(String fileName, long fileSize, String contentType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record AwsS3Properties(
String bucketName,
String accessKey,
String secretKey,
long maxFileSize,
int signatureDuration,
int maxFileNameLength,
String allowedExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public PresignResponse requestPresign(PresignRequest req) {
String originalFileName = req.originalFileName();
String contentType = req.contentType();
String extension = getExtensionOf(originalFileName);
long fileSize = req.fileSize();

s3ValidateService.validateFileWithThrowing(originalFileName, contentType);
s3ValidateService.validateFileWithThrowing(originalFileName, fileSize, contentType);
boolean isPdf = contentType.equals("application/pdf") && extension.equals(".pdf");

String uuid = UUID.randomUUID().toString();
Expand All @@ -87,7 +88,7 @@ public PresignResponse requestPresign(PresignRequest req) {
.bucket(awsS3Properties.bucketName())
.key(uploadKey)
.contentType(req.contentType())
.contentLength(req.fileSize())
.contentLength(fileSize)
.metadata(metadata))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ public void checkCloudFrontUrlWithThrowing(String url) {
}

@Override
public void validateFileWithThrowing(String fileName, String contentType) {
public void validateFileWithThrowing(String fileName, long fileSize, String contentType) {
int maxFileNameLength = awsS3Properties.maxFileNameLength();
String allowedExtensions = awsS3Properties.allowedExtensions();

if (fileSize > awsS3Properties.maxFileSize()) {
throw new CustomException(ExceptionMessage.OUT_OF_FILE_SIZE);
}
if (fileName == null) {
throw new CustomException(ExceptionMessage.FILE_NAME_NOT_EXIST);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum ExceptionMessage {
DEFAULT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "에러가 발생했습니다."),

// ## AWS ISSUE
OUT_OF_FILE_SIZE(HttpStatus.BAD_REQUEST, "허용되지 않은 파일 크기입니다."),
NO_FILE_UPLOADED(HttpStatus.BAD_REQUEST, "파일이 업로드되지 않았습니다."),
FILE_NAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "파일 이름이 존재하지 않습니다"),
FILE_NAME_TOO_LONG(HttpStatus.BAD_REQUEST, "파일 이름이 깁니다"),
Expand Down