1. PyCharm과 python 3.9.7 버전을 받는다.

    https://www.python.org/downloads/release/python-397/

    → 여기서 파이썬을 받는다

    받을때 아래 add python.exe 꼭 체크 해준다

    Untitled

  2. 해당 파이썬 파일 아무데나 다운받기 (git 에 올릴 예정이니 git에서 받아도 됨)

    main.py

    다운받은 경로

    application.properties에

    # python file path
    python.file.path=C:/Users/eunseo/Desktop/main.py
    

    이 부분에 추가하기

  3. intellij 켜기 → terminal 들어가기

    다음 명령어 순서대로 입력하기

  4. intellij에서 global → s3upload → imageService 에서 saveImageAndRemoveBg 메서드

    public String saveImageAndRemoveBg(MultipartFile multipartFile) throws IOException {
    
            if(multipartFile.isEmpty()) {
                throw new IllegalArgumentException("사진이 없으면 사진을 저장할 수 없습니다.");
            }
    
            String originalName = multipartFile.getOriginalFilename(); // 파일 이름
    
            // 파일명 중복을 피하기위해 날짜 추가
            String formatDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("-yyyyMMdd-HHmmss"));
            String fileName = originalName + formatDate;
    
            long size = multipartFile.getSize(); // 파일 크기
    
            ObjectMetadata objectMetaData = new ObjectMetadata();
            objectMetaData.setContentType(multipartFile.getContentType());
            objectMetaData.setContentLength(size);
    
            try {
                // S3에 업로드
                amazonS3Client.putObject(
                        new PutObjectRequest(S3Bucket, fileName, multipartFile.getInputStream(), objectMetaData)
                                .withCannedAcl(CannedAccessControlList.PublicRead)
                );
            } catch (AmazonClientException e) {
                throw new RuntimeException("S3에 이미지를 업로드하는데 실패했습니다.", e);
            }
    
            String imagePath = amazonS3Client.getUrl(S3Bucket, fileName).toString(); // 접근가능한 URL 가져오기
    
            if(imagePath == null) {
                throw new IllegalArgumentException("이미지 경로를 가져오지 못하였습니다.");
            }
    
            // 배경제거를 완료하면
            String processedImagePath = processImageAndReturnPath(imagePath);
            // 배경되기전 url은 삭제한다.
            deleteImage(imagePath);
    
            return processedImagePath;
        }
    

    이거로 수정해보고 postman으로 확인해보기 db에 이미지 사진 누끼 딴 사진으로 들어가 있으면 성공!