[英]How to manage User authorization to upload images to S3 using AWS Amplify and Cognito?
我创建了UserPool和Identity Pools,并成功执行了Signup和SignIn。 但是当我尝试访问S3上传图像时,我收到以下错误。
错误:com.amazonaws.services.s3.model.AmazonS3Exception:拒绝访问(服务:null;状态代码:403;错误代码:AccessDenied;
这是导致错误的代码段。
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
getApplicationContext(),
"MY_Identity_Pool_ID", // Identity pool ID
Regions.MY_Region// Region
);
TransferUtility transferUtility =
TransferUtility.builder()
.context(getApplicationContext())
.awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
.s3Client(new AmazonS3Client(credentialsProvider, Region.getRegion(Regions.AP_SOUTH_1)))
.build();
Log.d("imagepath", images.get(0).getPath());
TransferObserver uploadObserver =
transferUtility.upload(
"apples.jpeg",
new File(images.get(0).getPath()));
我通过将S3访问策略授予IAM中的授权角色来解决它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.