S3에 putObject시 SignatureDoesNotMatch 오류

2024. 5. 30. 12:01
728x90

 

 

 

업로드 시에 폴더를 지정하기 위해 bucketName의 자리에 bucket+ 내부에 있는 폴더이름으로 지정했다.

    fun uploadFile(file: MultipartFile, folder: String): String {
        val tempFile = File.createTempFile("upload-", file.originalFilename)
        val key = file.originalFilename
        file.transferTo(tempFile)

        val putObjectRequest = PutObjectRequest("$bucket/$folder", key, tempFile)
        amazonS3Client.putObject(putObjectRequest)
        tempFile.delete()

        return "$folder/$key"
    }

 

>> 그랬더니 이러한 에러가 났다. SignatureDoesNotMatch

There was an unexpected error (type=Internal Server Error, status=500).
The request signature we calculated does not match the signature you provided. Check your key and signing method. If you start to see this issue after you upgrade the SDK to 1.12.460 or later, it could be because the bucket provided contains '/'. See https://github.com/aws/aws-sdk-java/discussions/2976 for more details (Service: Amazon S3; Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: xxx; S3 Extended Request ID: xxx; Proxy: null)
com.amazonaws.services.s3.model.AmazonS3Exception: The request signature we calculated does not match the signature you provided. Check your key and signing method. If you start to see this issue after you upgrade the SDK to 1.12.460 or later, it could be because the bucket provided contains '/'. See https://github.com/aws/aws-sdk-java/discussions/2976 for more details (Service: Amazon S3; Status Code: 403; Error Code: SignatureDoesNotMatch; Request ID: xxx; S3 Extended Request ID: xxx; Proxy: null), S3 Extended Request ID: xxx at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1880)

 

근데 읽어보면 사인에 / 이 특수문자가 포함되어있으면 안된다고 하는데 > 내 키에도 역시 들어있긴 함

근데 아무리 발급해도 안없어져서 일단 
https://github.com/aws/aws-sdk-java/discussions/2976 여기서 detail을 볼수있다길래 봄

 

이러한 설명이 있었다. 

나도 putObject 시에 bucket/prefix, key 이런 형식으로 집어넣었다. 

이를 반영하여 고쳐봤다. 

** 

    fun uploadFile(file: MultipartFile, folder: String): String {
        val tempFile = File.createTempFile("upload-", file.originalFilename)
        val key = file.originalFilename
        file.transferTo(tempFile)

        val putObjectRequest = PutObjectRequest(bucket, "$folder/$key", tempFile)
        amazonS3Client.putObject(putObjectRequest)
        tempFile.delete()

        return "$folder/$key"
    }

 

>> 이렇게 고쳤더니 바로 해결~~

728x90