Skip to content

Commit

Permalink
Feat: PDFKey 추출해오는 메서드 및 파일이름 저장시 wallet address로 저장되게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jinno321 committed Aug 28, 2024
1 parent 94057f3 commit c0d783c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public ResponseEntity<String> getMetadata(@RequestParam String pdfUrl,
return ResponseEntity.ok().body(metadata);
}

@GetMapping("/get-pdfkey")
public ResponseEntity<String> getPdfKey(@RequestParam String pdfUrl,
@RequestParam int page) {
String metadata = s3StorageService.getPdfKeyForPage(pdfUrl, page);
return ResponseEntity.ok().body(metadata);
}



/*//스케줄러 용
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public String uploadPdf(MultipartFile file, Wallet wallet,String pdfInfo,String
}

private static String getFileName(MultipartFile file, Wallet wallet) {
return wallet.getAddress() + "_" + System.currentTimeMillis() + "_" + file.getOriginalFilename();
return wallet.getAddress() + "_" + System.currentTimeMillis() + "_" + wallet.getAddress();
}

private static String getEmptyFilename(Wallet wallet) {
Expand Down Expand Up @@ -320,6 +320,30 @@ public String getMetadataForPage(String pdfUrl, int pageNumber) {
return null; // 결과가 없거나 ':'가 없는 경우 null 반환
}

public String getPdfKeyForPage(String pdfUrl, int pageNumber) {
String fileName = extractKeyFromUrl(pdfUrl);

GetObjectRequest getRequest = GetObjectRequest.builder()
.bucket(bucketName)
.key(fileName)
.build();

GetObjectResponse getObjectResponse = s3Client.getObject(getRequest).response();

Map<String, String> metadata = getObjectResponse.metadata();

String pageKey = "page-" + pageNumber;

String result = metadata.get(pageKey);

// pdfKey 부분만 추출
if (result != null && result.contains(":")) {
return result.split(":")[1]; // ':'기준으로 분리
}

return null; // 결과가 없거나 ':'가 없는 경우 null 반환
}



public int getPdfPageCount(byte[] pdfBytes) throws IOException {
Expand Down

0 comments on commit c0d783c

Please sign in to comment.