在什么情况下文件不会从Android上传到aws S3

时间:2016-03-04 09:21:38

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

我试图从我的Android上传图片到AWS S3。问题是,当我运行此代码时,它不会显示任何错误,但文件仍未上传到S3。我使用本指南尝试上传我的图片 http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/s3transferutility.html 但它似乎没有用。它可能是什么情况下不上传?

            new Thread() {
                @Override
                public void run() {

                    // Initialize the Amazon Cognito credentials provider
                    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                            getApplicationContext(),
                            "us-east-1:????????????????d", // Identity Pool ID
                            Regions.US_EAST_1 // Region
                    );


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

                    // Set the region of your s3 bucket
                    s3.setRegion(Region.getRegion(Regions.DEFAULT_REGION));

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

                    //Upload a file to amazon s3

                    Log.i("imageFile", imageFile.toString());
                    TransferObserver observer = transferUtility.upload(
                            "foond",     /* The bucket to upload to */
                            "key",    /* The key for the uploaded object */
                            imageFile        /* The file where the data to upload exists */
                    );
                }
            }.start();

另外,万一有人要求,该文件不为空。我已经初步确定了它。当我记录imageFile时,它会打印出来 I / imageFile:/storage/emulated/0/DCIM/Camera/IMG_20160223_134442.jpg

另外,应该注意的是,当我来自加利福尼亚时,我必须选择我的位置为N. Virginia,如果这有任何区别的话。我不得不在另一个地区制作,因为我所在地区没有认知。

0 个答案:

没有答案