问题
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