首页 > 解决方案 > Android AWS sdk 无法上传

问题描述

我在 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。没有别的了。

如果无法上传图片,不应该有适当的错误吗?

我的日志猫:

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}]

标签: androidamazon-web-services

解决方案


推荐阅读