Amazon S3上传访问被拒绝

时间:2016-05-16 18:51:24

标签: android amazon-web-services amazon-s3

我已经坚持了很久。我看到其他人也有同样的问题,但我无法解决它。

我正在开发一个Android应用程序,它从相机拍摄照片,并将其上传到Amazon S3上的存储桶。这是我的代码:

  CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(),    /* get the context for the application */
                "MY_POOL_ID",    /* Identity Pool ID */
                Regions.US_EAST_1           /* Region for your identity pool--US_EAST_1 or EU_WEST_1*/
        );


        // Create an S3 client
        AmazonS3 s3 = new AmazonS3Client(credentialsProvider);

        s3.setRegion(Region.getRegion(Regions.US_EAST_1));

        TransferUtility transferUtility = new TransferUtility(s3, getApplicationContext());

        TransferObserver observer = transferUtility.upload(
                MY_BUCKET,     /* The bucket to upload to */
                OBJECT_KEY,    /* The key for the uploaded object */
                f        /* The file where the data to upload exists */
        );

我创建了一个桶。文件f,我将Bitmap从相机转换为文件。我的池ID有效,如果我更改它,我会收到错误pool not found;与桶相同。但是每次我尝试上传时都会收到此错误:

  

无法上传:11由于拒绝访问(服务:Amazon S3;状态   代码:403;错误代码:AccessDenied;请求ID:FD1B30F)

我是Amazon S3的初学者,我一次又一次地遵循他们的指示,但我无法解决这个问题。

我在清单中有这个:

<service


android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
        android:enabled="true" />

和正确的权限。

我需要做些什么来纠正这个问题?

2 个答案:

答案 0 :(得分:1)

检查您的存储分区权限,尝试完全打开它,看看您是否能够通过Android的SDK访问它。

查看AWS提供的策略生成器,以帮助您:

http://awspolicygen.s3.amazonaws.com/policygen.html

答案 1 :(得分:-3)

我的问题的答案是当我在我的设备Nexus 5上测试我的应用程序时会出现此问题。当我使用模拟器(Genymotion)时,它正常工作。然而,为什么它没有在我的真实设备上工作我不会&#39;知道。

相关问题