Android AWS sdk无法上传

时间:2018-06-12 09:04:53

标签: android amazon-web-services

我在MobileHub上创建了应用程序并集成了android。配置文件位于原始目录中。

致电后

AWSMobileClient.getInstance().initialize(context).execute();
BasicAWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, KEY_SECRET);
AmazonS3Client s3Client = new AmazonS3Client(credentials);

transferUtility = TransferUtility.builder()
                    .context(context.getApplicationContext())
                    .awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
                    .s3Client(s3Client)
                    .build();



TransferObserver uploadObserver =
                            transferUtility.upload(
                                    BUCKET_NAME,
                                    file.getName(),
                                    file);

uploadObserver.setTransferListener(new TransferListener() {
                        @Override
                        public void onStateChanged(int id, TransferState state) {
                            System.out.println("State changed:"+state);
                        }

                        @Override
                        public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
                            System.out.println("Progress.."+bytesCurrent);
                        }

                        @Override
                        public void onError(int id, Exception ex) {
                            System.out.println("error:"+ex);
                        }
                    });

我得到了

Welcome to AWS! You are connected successfully.
AWSMobileClient Initialize succeeded.

但是当我尝试上传任何文件时(从公共目录和私有文件),它只触发onProgressChanged一次,TransferState为IN_PROGRESS。别无其他。

如果无法上传图片,是否应该出现错误?

我的Logcat:

06-12 14:22:41.873 I: Welcome to AWS! You are connected successfully. 06-12 14:22:41.873 D: AWSMobileClient Initialize succeeded. 06-12 14:22:41.873 I: Welcome to AWS! You are connected successfully. 06-12 14:22:41.877 I: registering receiver 06-12 14:22:41.955 I: State changed:IN_PROGRESS 06-12 14:22:41.960 W: finishComposingText on inactive InputConnection finishComposingText on inactive InputConnection finishComposingText on inactive InputConnection 06-12 14:22:46.844 V: Inactivity, disconnecting from the service 06-12 14:22:46.845 I: Sending crashes 06-12 14:23:18.221 V: Recording user engagement, ms: 36408 06-12 14:23:18.223 V: Connecting to remote service 06-12 14:23:18.230 V: Activity paused, time: 22740592 06-12 14:23:18.237 D: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=36408, firebase_screen_class(_sc)=AdminActivity, firebase_screen_id(_si)=-1968217097067733732}]

1 个答案:

答案 0 :(得分:0)

按照以下教程链接在aws s3上传数据

https://www.numetriclabz.com/integrate-amazon-s3-to-android-tutorial/