Skip to content

Commit

Permalink
Fix: 파일 업로드 로직 Rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey-Oh committed Mar 12, 2024
1 parent 4a8383d commit 21f66b7
Showing 1 changed file with 1 addition and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public FileInfoDTO uploadFile(String path, MultipartFile uploadFile) {
final ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(uploadFile.getContentType());
objectMetadata.setContentLength(uploadFile.getSize());

TransferManager transferManager = TransferManagerBuilder.standard().withS3Client(amazonS3).build();
try {
final String uploadPath = DEFAULT_UPLOAD_PATH + "/" + path;
final String uploadFileName = createUploadFileName(uploadFile);
Expand All @@ -79,23 +77,13 @@ public FileInfoDTO uploadFile(String path, MultipartFile uploadFile) {
final String ext = FileUtil.getFileExt(uploadFile);
final long size = uploadFile.getSize();

PutObjectRequest request = new PutObjectRequest(bucketName, uploadPath + "/" + uploadFileName, uploadFile.getInputStream(), objectMetadata);
Upload upload = transferManager.upload(request);

try {
upload.waitForCompletion();
} catch (AmazonClientException | InterruptedException e) {
log.error(e.getMessage());
}

amazonS3.putObject(new PutObjectRequest(bucketName, uploadPath + "/" + uploadFileName, uploadFile.getInputStream(), objectMetadata));
final String uploadFullPath = endpoint + uploadPath + "/" + uploadFileName;

return new FileInfoDTO(uploadPath, uploadFileName, originFileName, uploadFullPath, contentType, ext, size);
} catch (IOException e) {
log.error(e.getMessage());
throw new FileUploadException();
} finally {
transferManager.shutdownNow();
}
}

Expand Down

0 comments on commit 21f66b7

Please sign in to comment.