Getting access denied error on uploading the file to Amazon S3

孤街醉人 提交于 2021-01-29 05:44:08

问题


Getting access denied error:

Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: AEB65D41FEB958C7; S3 Extended Request ID: jhCxO/Mv4MTxMRjvkM3bHVJ3dhb7TBeK0k7qHFUY3Q/RFhF591mRLeIzPXUEF0EdtgX9FNJXSq4=), S3 Extended Request ID: jhCxO/Mv4MTxMRjvkM3bHVJ3dhb7TBeK0k7qHFUY3Q/RFhF591mRLeIzPXUEF0EdtgX9FNJXSq4=File Upload Exception:Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: AEB65D41FEB958C7;

when trying to upload the file. My code is:

private void uploadFile(String fileName, File file) {
    System.out.print("clouldfileservice: putREqeust");
    PutObjectRequest request = new PutObjectRequest(this.bucketName, fileName, file)
            .withCannedAcl(CannedAccessControlList.PublicRead);
    try {
        PutObjectResult result = this.s3Client.putObject(request);
    } catch (Exception e) {
        System.out.print("File Upload Exception:" + e.toString());
        System.out.print("File Upload Exception:" + e.getLocalizedMessage());

    }

}

回答1:


Error indicates that you don't have an access to S3 Bucket.

Proper solution:

Go to policy generator and generate one, it's a configuration that defines who has access to this resource.

Paste that policy to Bucket settings > permissions > Bucket Policy and save.

Quick & dirty solution:

Check "list" and "write" checkboxes in: Bucket settings > Permissions > Public Access > Everyone.

Go to: Bucket settings > permissions > Bucket Policy



来源:https://stackoverflow.com/questions/56299192/getting-access-denied-error-on-uploading-the-file-to-amazon-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!