Skip to content

Commit

Permalink
feat: 로컬 storage 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
SJ70 committed Aug 14, 2024
1 parent 4a14cd0 commit 062e331
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions src/main/java/com/j9/bestmoments/service/LocalStorageService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.j9.bestmoments.service;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
@Slf4j
public class LocalStorageService implements StorageService {

@Value("${storage.local.dir}")
private String dir;

@Override
public String uploadFile(MultipartFile file, String fileName) {
try {
Path path = Paths.get(dir + fileName);
if (!path.toFile().exists()) {
path.toFile().mkdirs();
}
File destinationFile = new File(dir, fileName);
file.transferTo(destinationFile);
return destinationFile.getAbsolutePath();

} catch (IOException e) {
e.printStackTrace();
return "파일 업로드에 실패했습니다.";
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/j9/bestmoments/service/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class VideoService {

private final VideoRepository videoRepository;
private final StorageService storageService;
private final LocalStorageService storageService;

@Transactional
public Video upload(Member member, VideoCreateDto createDto) {
Expand Down

0 comments on commit 062e331

Please sign in to comment.