Skip to content

Commit

Permalink
Merge pull request #175 from TrainingDiary/fix/change-video
Browse files Browse the repository at this point in the history
동영상 업로드 코드 수정
  • Loading branch information
guswnee00 authored Jul 29, 2024
2 parents afbc2d5 + 2bb1b33 commit 4563277
Showing 1 changed file with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ public String uploadThumbnail(String encodedVideoUrl, String uuid)
String thumbPath = VideoUtil.generateThumbnail(encodedVideoUrl, tmpPath);

S3Resource thumbS3Resource;
File tempFile = new File(thumbPath);

try (InputStream inputStream = new FileInputStream(thumbPath)) {
try (InputStream inputStream = new FileInputStream(tempFile)) {
thumbS3Resource = s3Operations.upload(bucket, thumbnailKey, inputStream,
ObjectMetadata.builder().contentType("image/png").build());
} finally {
if (tempFile.exists()) {
tempFile.delete();
}
}

// 임시 파일 삭제
new File(tmpPath).delete();

return thumbS3Resource.getURL().toExternalForm();
}

Expand All @@ -83,22 +85,30 @@ private String encodeAndUploadVideo(
String extension
) throws IOException, InterruptedException {
// 임시 파일 경로 설정
String tmpPath = "/tmp/original_" + originalKey;
String tmpPath = "/tmp/" + originalKey;

File tempFile = null;
S3Resource videoS3Resource;
if ("mov".equalsIgnoreCase(extension)) {
String encodedVideoPath = VideoUtil.encodeVideo(tempVideoUrl, tmpPath);
try (InputStream inputStream = new FileInputStream(encodedVideoPath)) {
videoS3Resource = s3Operations.upload(bucket, originalKey, inputStream,
ObjectMetadata.builder().contentType(contentType).build());
try {
if ("mov".equalsIgnoreCase(extension)) {
String encodedVideoPath = VideoUtil.encodeVideo(tempVideoUrl, tmpPath);
tempFile = new File(encodedVideoPath);
try (InputStream inputStream = new FileInputStream(tempFile)) {
videoS3Resource = s3Operations.upload(bucket, originalKey, inputStream,
ObjectMetadata.builder().contentType(contentType).build());
}
} else {
// MOV가 아닌 경우 원본을 그대로 사용
try (InputStream inputStream = new URL(tempVideoUrl).openStream()) {
videoS3Resource = s3Operations.upload(bucket, originalKey, inputStream,
ObjectMetadata.builder().contentType(contentType).build());
}
}
// 임시 파일 삭제
new File(tmpPath).delete();
} else {
// MOV가 아닌 경우 원본을 그대로 사용
try (InputStream inputStream = new URL(tempVideoUrl).openStream()) {
videoS3Resource = s3Operations.upload(bucket, originalKey, inputStream,
ObjectMetadata.builder().contentType(contentType).build());
} finally {
if (tempFile != null && tempFile.exists()) {
tempFile.delete();
} else {
new File(tmpPath).delete();
}
}

Expand Down

0 comments on commit 4563277

Please sign in to comment.