Skip to content

Commit

Permalink
refactor: 이미지 업로드 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hgo641 committed Oct 19, 2023
1 parent 4fb352a commit 4dc0804
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import com.amazonaws.services.s3.model.ObjectMetadata;
import hanglog.global.exception.ImageException;
import hanglog.image.domain.ImageFile;
import hanglog.image.domain.S3ImageEvent;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -22,6 +24,7 @@ public class ImageUploader {
private static final String CACHE_CONTROL_VALUE = "max-age=3153600";

private final AmazonS3 s3Client;
private final ApplicationEventPublisher publisher;

@Value("${cloud.aws.s3.bucket}")
private String bucket;
Expand All @@ -30,9 +33,14 @@ public class ImageUploader {
private String folder;

public List<String> uploadImages(final List<ImageFile> imageFiles) {
return imageFiles.stream()
.map(this::uploadImage)
.toList();
try {
return imageFiles.stream()
.map(this::uploadImage)
.toList();
} catch (final ImageException e) {
imageFiles.forEach(imageFile -> publisher.publishEvent(new S3ImageEvent(imageFile.getHashedName())));
throw e;
}
}

private String uploadImage(final ImageFile imageFile) {
Expand Down

0 comments on commit 4dc0804

Please sign in to comment.