簡體   English   中英

Amazon S3 訪問被拒絕 - Java SpringBoot

[英]Amazon S3 Access Denied - Java SpringBoot

我需要在aws上設置我的圖像,我已經將我的存儲桶配置為公開的,但我剛剛得到“AccessDenied”

public boolean saveImage(String nome, String base64){
        try {
            byte[] imageBytes = Base64.getDecoder().decode(base64.split(",")[1]);
            BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageBytes));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ImageIO.write(image, "png", baos);
            byte[] bytes = baos.toByteArray();
            String fileName = nome+".png";
            BasicAWSCredentials awsCreds = new BasicAWSCredentials(acessKey, secretKey);
            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, new ByteArrayInputStream(bytes), new ObjectMetadata());
            AmazonS3 s3Client =
                    AmazonS3ClientBuilder.standard().withRegion("sa-east-1")
                            .withCredentials(new
                                    AWSStaticCredentialsProvider(awsCreds))
                            .build();
            s3Client.putObject(putObjectRequest);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

我的存儲桶 100% 公開

com.amazonaws.services.s3.model.AmazonS3Exception: Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: ""; S3 Extended Request ID: ""; Proxy: null), S3 Extended Request ID: ""

這可能是由於您的 IAM 用戶策略中缺乏對 s3 執行操作的權限。請確保您使用的 IAM 用戶憑證應具有足夠的權限來執行所需的操作。 另外,關於 S3 中 403 錯誤的原因和解決方案,您可以參考 AWS 的這篇文章 - https://aws.amazon.com/premiumsupport/knowledge-center/s3-troubleshoot-403/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM