Skip to content

Commit

Permalink
feat: 동영상 등록 시 썸네일 업로드
Browse files Browse the repository at this point in the history
  • Loading branch information
SJ70 committed Aug 14, 2024
1 parent 1f71f59 commit ee9c214
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/j9/bestmoments/service/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ public Video upload(Member member, VideoCreateDto createDto) {
.title(createDto.title())
.description(createDto.description())
.build();

String videoName = FileNameGenerator.generateVideoFileName(video);
String videoUrl = storageService.uploadFile(createDto.video(), videoName);
video.setVideoUrl(videoUrl);

String thumbnailName = FileNameGenerator.generateThumbnailImageFileName(video);
String thumbnailUrl = storageService.uploadFile(createDto.thumbnail(), thumbnailName);
video.setThumbnailUrl(thumbnailUrl);

videoRepository.save(video);
return video;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/j9/bestmoments/util/FileNameGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public static String generateVideoFileName(Video video) {
return String.format("video/%s/video-origin", videoId);
}

public static String generateThumbnailImageFileName(Video video) {
String videoId = video.getId().toString();
String dateString = generateDateString();
return String.format("video/%s/thumbnail-%s", videoId, dateString);
}

private static String generateDateString() {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
Expand Down

0 comments on commit ee9c214

Please sign in to comment.