我尝试使用'TransferUtility'将文件上传到AWS s3存储桶,并且我已在Mobile HUB上注册了该应用程序,并将'awsconfiguration.json'文件粘贴到文档中提到的res / raw中。

我得到了这个日志:


  I / AWSMobileClient:欢迎使用AWS!您已成功连接。


当我在“ onCreate()”中调用它时

AWSMobileClient.getInstance().initialize(this).execute();


执行此代码时出现此错误

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

TransferObserver uploadObserver =
                    transferUtility.upload(
                            s3Bucket+"/"+s3Folder+"/"+fileName,
                            new File(fileUrl));


错误:


  E / AndroidRuntime:致命异常:main
                                                                             流程:xxxx.xxxxx.com,PID:28698
                                                                             java.lang.IllegalArgumentException:无法读取S3TransferUtility
  请检查您的setup或awsconfiguration.json文件
                                                                                 在
  com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility $ Builder.build(TransferUtility.java:248)


有人可以帮我这件事,并指导我这里做错了什么吗?

感谢您的努力。谢谢

最佳答案

您提到的错误来自这里:https://github.com/aws/aws-sdk-android/blob/master/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferUtility.java#L248

此错误表示您有awsconfiguration.json文件,但json文件中可能没有S3TransferUtility块。您可以检查json文件中是否有所需的块吗?

10-08 17:02