Skip to content

Commit

Permalink
[fix] Dall-e 생성된 이미지 S3 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
hysong4u committed May 5, 2024
1 parent 77fbbe8 commit e1d1825
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public ResponseEntity<SuccessResponse<?>> generateResponse(@RequestParam(name =
//수형, 단어 이미지 생성
List<String> signImageUrls = imageCrawlerService.crawlImageUrls(searchWord);
byte[] mergeImages = imageCrawlerService.mergeImages(signImageUrls);
String signImageUrl = imageCrawlerService.uploadFile(mergeImages, searchWord + ".jpg");
String generatedImageUrl = imageCrawlerService.generateImage(searchWord);;
String signImageUrl = imageCrawlerService.uploadFile(mergeImages, searchWord + "sign.jpg");
String generatedImageUrl = imageCrawlerService.generateImage(searchWord);
String ImageUrl = imageCrawlerService.uploadFileFromUrl(generatedImageUrl, searchWord + ".jpg");

//cardId 생성
cardService.registerCard(searchWord, signImageUrl);
Expand All @@ -55,7 +56,7 @@ public ResponseEntity<SuccessResponse<?>> generateResponse(@RequestParam(name =
//수형 동작 설명
String generatesignLanguageDescription= geminiService.generateSignDescription(searchWord);

WordDatailsResponseDto wordDatailsResponse = new WordDatailsResponseDto(cardId, searchWord, descriptionResponse.get(0).description(),descriptionResponse.get(0).partsOfSeech(), generatedImageUrl, signImageUrl,generatesignLanguageDescription );
WordDatailsResponseDto wordDatailsResponse = new WordDatailsResponseDto(cardId, searchWord, descriptionResponse.get(0).description(),descriptionResponse.get(0).partsOfSeech(), ImageUrl, signImageUrl,generatesignLanguageDescription );

return SuccessResponse.ok(wordDatailsResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
Expand Down Expand Up @@ -192,6 +193,20 @@ public String generateImage(String searchWord) throws IOException {
return extractImageUrl(imageURL);
}

public String uploadFileFromUrl(String fileUrl, String fileName) throws IOException {
URL url = new URL(fileUrl);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (InputStream inputStream = url.openStream()) {
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
}

return uploadFile(outputStream.toByteArray(), fileName);
}

//json 파싱
public String extractImageUrl(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper();
Expand Down

0 comments on commit e1d1825

Please sign in to comment.