-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/7-uploadStory' into feature/7-storyLike
- Loading branch information
Showing
23 changed files
with
800 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
place/src/main/java/com/umc/place/common/config/AWSConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.umc.place.common.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
|
||
@Configuration | ||
public class AWSConfig { | ||
|
||
@Value("${cloud.aws.credentials.accessKey}") | ||
private String accessKey; | ||
|
||
@Value("${cloud.aws.credentials.secretKey}") | ||
private String secretKey; | ||
|
||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey); | ||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(basicAWSCredentials)) | ||
.build(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
place/src/main/java/com/umc/place/common/controller/FileUploadController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.umc.place.common.controller; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.umc.place.common.service.S3Upload; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class FileUploadController { | ||
|
||
private final S3Upload s3Upload; | ||
|
||
@PostMapping("/upload") | ||
public ResponseEntity<Object> uploadFile(MultipartFile[] multipartFileLis) throws IOException { | ||
return ResponseEntity.ok( | ||
s3Upload.upload(multipartFileLis) | ||
); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
place/src/main/java/com/umc/place/common/service/S3Upload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.umc.place.common.service; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class S3Upload { | ||
|
||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucket; | ||
|
||
private final AmazonS3Client amazonS3Client; | ||
; | ||
|
||
//https://jforj.tistory.com/261 | ||
public List<String> upload(MultipartFile[] multipartFileList) throws IOException { | ||
List<String> imagePathList = new ArrayList<>(); | ||
|
||
for (MultipartFile multipartFile : multipartFileList) { | ||
String originalName = multipartFile.getOriginalFilename(); // 파일 이름 | ||
long size = multipartFile.getSize(); // 파일 크기 | ||
|
||
ObjectMetadata objectMetaData = new ObjectMetadata(); | ||
objectMetaData.setContentType(multipartFile.getContentType()); | ||
objectMetaData.setContentLength(size); | ||
|
||
// S3에 업로드 | ||
amazonS3Client.putObject( | ||
new PutObjectRequest(bucket, originalName, multipartFile.getInputStream(), objectMetaData) | ||
.withCannedAcl(CannedAccessControlList.PublicRead) | ||
); | ||
|
||
String imagePath = amazonS3Client.getUrl(bucket, originalName).toString(); // 접근가능한 URL 가져오기 | ||
imagePathList.add(imagePath); | ||
} | ||
return imagePathList; | ||
} | ||
} | ||
|
||
// String s3FileName = UUID.randomUUID() + "-" + multipartFile.getOriginalFilename(); | ||
// | ||
// ObjectMetadata objMeta = new ObjectMetadata(); | ||
// objMeta.setContentLength(multipartFile.getInputStream().available()); | ||
// | ||
// amazonS3.putObject(bucket, s3FileName, multipartFile.getInputStream(), objMeta); | ||
// | ||
// return amazonS3.getUrl(bucket, s3FileName).toString(); | ||
// for(MultipartFile multipartFile: multipartFileList) { | ||
// String originalName = multipartFile.getOriginalFilename(); // 파일 이름 | ||
// long size = multipartFile.getSize(); // 파일 크기 | ||
// | ||
// ObjectMetadata objectMetaData = new ObjectMetadata(); | ||
// objectMetaData.setContentType(multipartFile.getContentType()); | ||
// objectMetaData.setContentLength(size); | ||
// | ||
// // S3에 업로드 | ||
// amazonS3Client.putObject( | ||
// new PutObjectRequest(S3Bucket, originalName, multipartFile.getInputStream(), objectMetaData) | ||
// .withCannedAcl(CannedAccessControlList.PublicRead) | ||
// ); | ||
// | ||
// String imagePath = amazonS3Client.getUrl(S3Bucket, originalName).toString(); // 접근가능한 URL 가져오기 | ||
// imagePathList.add(imagePath); | ||
// } | ||
// | ||
// return new ResponseEntity<Object>(imagePathList, HttpStatus.OK); |
39 changes: 39 additions & 0 deletions
39
place/src/main/java/com/umc/place/exhibition/dto/SearchExhibitionsByNameResDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.umc.place.exhibition.dto; | ||
|
||
import com.umc.place.exhibition.entity.Exhibition; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class SearchExhibitionsByNameResDto { | ||
|
||
private List<SearchedExhibitionByName> searchedExhibitions = new ArrayList(); | ||
|
||
@Builder | ||
public SearchExhibitionsByNameResDto(Page<Exhibition> exhibitions) { | ||
this.searchedExhibitions | ||
= exhibitions.stream() | ||
.map(exhibition -> new SearchedExhibitionByName(exhibition)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public static class SearchedExhibitionByName { | ||
private Long exhibitionIdx; | ||
private String exhibitionName; | ||
|
||
@Builder | ||
public SearchedExhibitionByName(Exhibition exhibition) { | ||
this.exhibitionIdx = exhibition.getExhibitionIdx(); | ||
this.exhibitionName = exhibition.getExhibitionName(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
place/src/main/java/com/umc/place/user/OAuth2/dto/KakaoTokenResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.umc.place.user.OAuth2.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class KakaoTokenResponse { | ||
private String token_type; | ||
private String access_token; | ||
private int expires_in; | ||
private String refresh_token; | ||
private int refresh_token_expires_in; | ||
private String scope; | ||
} |
Oops, something went wrong.