Skip to content

Commit

Permalink
chore: Add timestamp to file names in generateFileName method
Browse files Browse the repository at this point in the history
  • Loading branch information
minjoon-98 committed Jul 24, 2024
1 parent d500c51 commit cf1f455
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/ongjong/namanmoo/service/AwsS3Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -131,7 +134,11 @@ private Optional<File> convertFile(MultipartFile file) throws IOException {
* @return String 고유한 파일 이름
*/
private String generateFileName(File uploadFile, String fileType) {
return fileType + "/" + UUID.randomUUID() + "_" + uploadFile.getName();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")
.withZone(ZoneId.systemDefault());
String formattedDate = formatter.format(Instant.now());

return fileType + "/" + UUID.randomUUID() + "_" + formattedDate + "_" + uploadFile.getName();
}

/**
Expand Down

0 comments on commit cf1f455

Please sign in to comment.