-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 지원서 작성 시 이메일 알림 * feat: 지원서 작성 시 사진 업로드
- Loading branch information
1 parent
290d648
commit 879e7c0
Showing
7 changed files
with
131 additions
and
3 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
13 changes: 13 additions & 0 deletions
13
src/main/java/yonseigolf/server/apply/dto/response/ImageResponse.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 yonseigolf.server.apply.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ImageResponse { | ||
|
||
private String image; | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/yonseigolf/server/apply/image/ImageService.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,54 @@ | ||
package yonseigolf.server.apply.image; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest; | ||
|
||
import java.io.IOException; | ||
|
||
@Service | ||
public class ImageService { | ||
|
||
private final S3Client s3Client; | ||
@Value("${AWS_S3_BUCKET}") | ||
private String bucketName; | ||
|
||
@Autowired | ||
public ImageService(S3Client s3Client) { | ||
|
||
this.s3Client = s3Client; | ||
} | ||
|
||
public String uploadImage(MultipartFile file, String randomId) { | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
String fileName = file.getOriginalFilename() + randomId; | ||
String contentType = file.getContentType(); | ||
|
||
// Upload file | ||
PutObjectRequest putObjectRequest = PutObjectRequest.builder() | ||
.bucket(bucketName) | ||
.key("store-image/" + fileName) | ||
.acl("public-read") | ||
.contentDisposition("inline") | ||
.contentType(contentType) | ||
.build(); | ||
|
||
String url = sb.append("https://") | ||
.append(bucketName) | ||
.append(".s3.ap-northeast-2.amazonaws.com/store-image/") | ||
.append(fileName) | ||
.toString(); | ||
|
||
try { | ||
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(file.getInputStream(), file.getSize())); | ||
return url; | ||
} catch (IOException e) { | ||
throw new IllegalStateException("Failed to upload file", e); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package yonseigolf.server.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
|
||
@Configuration | ||
public class AwsConfig { | ||
|
||
@Value("${AWS_ACCESS_KEY}") | ||
private String awsAccessKey; | ||
@Value("${AWS_SECRET_ACCESS_KEY}") | ||
private String awsSecretKey; | ||
@Value("${AWS_REGION}") | ||
private String region; | ||
|
||
@Bean | ||
public S3Client s3Client() { | ||
return S3Client.builder() | ||
.region(Region.of(region)) | ||
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(awsAccessKey, awsSecretKey))) | ||
.build(); | ||
} | ||
} |
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