-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from AR-TTUBEOG/feature/76-2
[Feature] 이미지 멀티파트폼 구현
- Loading branch information
Showing
23 changed files
with
576 additions
and
254 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/ttubeog/domain/UuidImage/domain/UuidImage.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,40 @@ | ||
package com.ttubeog.domain.UuidImage.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@Getter | ||
@Builder | ||
@Table(name = "uuid_image") | ||
public class UuidImage { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
@Column(unique = true) | ||
private String uuid; | ||
|
||
@Column(name = "image_url") | ||
private String imageUrl; | ||
|
||
public UuidImage(Long id, String uuid, String imageUrl) { | ||
this.id = id; | ||
this.uuid = uuid; | ||
this.imageUrl = imageUrl; | ||
} | ||
|
||
public void updateImageUrl(String imageUrl) { | ||
this.imageUrl = imageUrl; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/ttubeog/domain/UuidImage/domain/repository/UuidImageRepository.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,7 @@ | ||
package com.ttubeog.domain.UuidImage.domain.repository; | ||
|
||
import com.ttubeog.domain.UuidImage.domain.UuidImage; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UuidImageRepository extends JpaRepository<UuidImage, Long> { | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/ttubeog/domain/aws/s3/AmazonS3Manager.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,48 @@ | ||
package com.ttubeog.domain.aws.s3; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import com.ttubeog.domain.UuidImage.domain.UuidImage; | ||
import com.ttubeog.domain.image.domain.Image; | ||
import com.ttubeog.global.config.AmazonConfig; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class AmazonS3Manager { | ||
|
||
private final AmazonS3 amazonS3; | ||
|
||
private final AmazonConfig amazonConfig; | ||
|
||
public String uploadFile(String keyName, MultipartFile file) { | ||
ObjectMetadata metadata = new ObjectMetadata(); | ||
metadata.setContentLength(file.getSize()); | ||
try { | ||
amazonS3.putObject(new PutObjectRequest(amazonConfig.getBucket(), keyName, file.getInputStream(), metadata)); | ||
}catch (IOException e) { | ||
log.error("error at AmazonS3Manager uploadFile : {}", (Object) e.getStackTrace()); | ||
} | ||
|
||
return amazonS3.getUrl(amazonConfig.getBucket(), keyName).toString(); | ||
} | ||
|
||
public String generateSpotKeyName(Image image) { | ||
return amazonConfig.getSpotPath() + '/' + image.getUuid(); | ||
} | ||
|
||
public String generateStoreKeyName(Image image) { | ||
return amazonConfig.getStorePath() + '/' + image.getUuid(); | ||
} | ||
|
||
public String generateGuestBookKeyName(Image image) { | ||
return amazonConfig.getGuestBookPath() + '/' + image.getUuid(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/ttubeog/domain/aws/s3/S3PhotoService.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,26 @@ | ||
package com.ttubeog.domain.aws.s3; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.S3ObjectResource; | ||
import com.amazonaws.services.s3.model.S3Object; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
@Service | ||
public class S3PhotoService { | ||
|
||
private final AmazonS3 amazonS3; | ||
|
||
public S3PhotoService(AmazonS3 amazonS3) { | ||
this.amazonS3 = amazonS3; | ||
} | ||
|
||
public InputStream downloadPhotoFromS3(String bucketName, String key) throws IOException { | ||
S3Object object = amazonS3.getObject(bucketName, key); | ||
|
||
return new ByteArrayInputStream(object.getObjectContent().readAllBytes()); | ||
} | ||
} |
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
Oops, something went wrong.