我正在尝试在Amazon S3上上传文件,但是它返回此错误:
com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: 26B9B4844CEA580C), S3 Extended Request ID: S0Ds3cvubCSZTAd1ESUG5rMRifGLHRAHBviyUHzDVI5W8FQxtRDMBNSrhVme6K86UryWxqORv30=
我已经在AWS上配置了IAM和存储桶,并且使用了良好的访问/秘密(一个aws给了我)。有什么问题?谢谢!
S3Client代码:
s3client = AmazonS3ClientBuilder
.standard()
.withRegion(Regions.CA_CENTRAL_1) // The first region to try your request against
.withForceGlobalBucketAccessEnabled(true) // If a bucket is in a different region, try again in the correct region
.withCredentials(AWSStaticCredentialsProvider(BasicAWSCredentials(accessKey, secretKey)))
.build()
上传文件代码:
private fun uploadFileTos3bucket(fileName: String, file: File) {
s3client.putObject(PutObjectRequest(bucketName, fileName, file)
.withCannedAcl(CannedAccessControlList.PublicRead))
}
IAM用户: