Skip to content

Commit

Permalink
Merge pull request #49 from NU-BIM/refactor/album/presignedurl
Browse files Browse the repository at this point in the history
S3 Presigned URL 생성 시 컨텐츠 타입 검증 추가
  • Loading branch information
Aram-su authored Sep 6, 2024
2 parents 2acfcb8 + eac93b1 commit 5ac01cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@
import org.springframework.stereotype.Service;

import com.soyeon.nubim.common.util.aws.S3PresignedUrlGenerator;
import com.soyeon.nubim.domain.album.exception.InvalidContentTypeException;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class AlbumPhotoUploadUrlService {

public static final String MIME_TYPE_IMAGE = "image";
private final S3PresignedUrlGenerator s3PresignedUrlGenerator;

public List<String> generatePhotoUploadUrlsWithRandomPath(List<String> contentTypes) {
validateContentTypes(contentTypes);
return s3PresignedUrlGenerator.generatePresignedUrls(contentTypes);
}

public List<String> generatePhotoUploadUrlsWithCustomPath(List<String> contentTypes, String uploadPath) {
validateContentTypes(contentTypes);
return s3PresignedUrlGenerator.generatePresignedUrls(contentTypes, uploadPath);
}

private void validateContentTypes(List<String> contentTypes) {
for (String contentType : contentTypes) {
if (!contentType.startsWith(MIME_TYPE_IMAGE)) {
throw new InvalidContentTypeException("Invalid content type: " + contentType);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.soyeon.nubim.domain.album.exception;

import org.springframework.http.HttpStatus;
import org.springframework.web.server.ResponseStatusException;

public class InvalidContentTypeException extends ResponseStatusException {
public InvalidContentTypeException(String message) {
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "Invalid content type: " + message);
}
}

0 comments on commit 5ac01cb

Please sign in to comment.