Skip to content

Commit

Permalink
#18 refactor: imagePath만 반환하게 하기
Browse files Browse the repository at this point in the history
  • Loading branch information
lsn5963 committed Aug 21, 2023
1 parent 60aa6bd commit 4f11bbc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class FileUploadController {

private final S3Upload s3Upload;

@PostMapping("/upload/{location}/{idx}")
public BaseResponse<Object> uploadFile(MultipartFile multipartFile, @PathVariable String location, @PathVariable Long idx) throws IOException, BaseException {
s3Upload.upload(multipartFile,location,idx);
return new BaseResponse<>(ResponseEntity.ok("업로드 성공"));
@PostMapping("/upload/{location}")
public BaseResponse<Object> uploadFile(MultipartFile multipartFile, @PathVariable String location) throws IOException, BaseException {

return new BaseResponse<>(s3Upload.upload(multipartFile,location));
}


Expand Down
21 changes: 0 additions & 21 deletions place/src/main/java/com/umc/place/common/entity/S3.java

This file was deleted.

This file was deleted.

23 changes: 12 additions & 11 deletions place/src/main/java/com/umc/place/common/service/S3Upload.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public class S3Upload {
private final StoryRepository storyRepository;

//https://jforj.tistory.com/261
public void upload(MultipartFile multipartFile, String location,Long idx) throws IOException, BaseException {
public String upload(MultipartFile multipartFile, String location) throws IOException, BaseException {

String originalName = UUID.randomUUID() + multipartFile.getOriginalFilename(); // 파일 이름
String originalName = location + "/" + UUID.randomUUID() + multipartFile.getOriginalFilename(); // 파일 이름
long size = multipartFile.getSize(); // 파일 크기

ObjectMetadata objectMetaData = new ObjectMetadata();
Expand All @@ -48,16 +48,17 @@ public void upload(MultipartFile multipartFile, String location,Long idx) throws
);
String imagePath = amazonS3Client.getUrl(bucket, originalName).toString(); // 접근가능한 URL 가져오기
System.out.println("imagePath = " + imagePath);

if (location.equals("profile")) { // 프로필일 경우
User user = userRepository.findByUserIdxAndStatusEquals(idx,ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); // 유저에 저장
user.setUserImg(imagePath);
}
if (location.equals("story")) { // 스토리일 경우
Story story = storyRepository.findById(idx).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); // 스토리에 저장
story.setStoryImg(imagePath);
}
return imagePath;
}
}

// if (location.equals("profile")) { // 프로필일 경우
// User user = userRepository.findByUserIdxAndStatusEquals(idx,ACTIVE).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); // 유저에 저장
// user.setUserImg(imagePath);
// }
// if (location.equals("story")) { // 스토리일 경우
// Story story = storyRepository.findById(idx).orElseThrow(() -> new BaseException(INVALID_USER_IDX)); // 스토리에 저장
// story.setStoryImg(imagePath);
// }


0 comments on commit 4f11bbc

Please sign in to comment.