Skip to content

Commit

Permalink
refactor: 저장 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
fromitive committed Dec 1, 2024
1 parent 958b282 commit 97dc262
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ public class LocalStorageService implements StorageService {
@Value("${storage.path}")
private String storagePath;

LocalStorageService(String redirectUrl, String storagePath) {
this.redirectUrl = redirectUrl;
this.storagePath = storagePath;
}

@Override
public String uploadFile(MultipartFile file) {
String extension = getFileExtension(file);
validateFileExtension(extension);
String newFilename = UUID.randomUUID().toString();
storeFile(file, newFilename);
return createUri(newFilename);
}

private void storeFile(MultipartFile file, String newFilename) {
try {
String extension = getFileExtension(file);
validateFileExtension(extension);
String newFilename = UUID.randomUUID() + "." + extension;
Path uploadPath = Paths.get(storagePath);
Path filePath = uploadPath.resolve(newFilename);
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
return createUri(filePath.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 97dc262

Please sign in to comment.