Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android AWS S3-将sdk版本从“2.2.+”升级到“2.6.7”后对象“不存在”_Android_Amazon Web Services_Amazon S3 - Fatal编程技术网

Android AWS S3-将sdk版本从“2.2.+”升级到“2.6.7”后对象“不存在”

Android AWS S3-将sdk版本从“2.2.+”升级到“2.6.7”后对象“不存在”,android,amazon-web-services,amazon-s3,Android,Amazon Web Services,Amazon S3,我有一个使用S3的Android应用程序的代码。我在将近一年前建立了它,它在应用程序依赖项中声明: dependencies { compile 'com.amazonaws:aws-android-sdk-core:2.2.+' compile 'com.amazonaws:aws-android-sdk-s3:2.2.+' } 撰写本文时的当前版本为 现在,我的问题是: //This code came from the Mobile Hub sample applicat

我有一个使用S3的Android应用程序的代码。我在将近一年前建立了它,它在应用程序依赖项中声明:

dependencies {
    compile 'com.amazonaws:aws-android-sdk-core:2.2.+'
    compile 'com.amazonaws:aws-android-sdk-s3:2.2.+'
}
撰写本文时的当前版本为

现在,我的问题是:

//This code came from the Mobile Hub sample application

//Obtain a reference to the mobile client. It is created in the Application class.
final AWSMobileClient awsMobileClient = AWSMobileClient.defaultMobileClient();

//Obtain a reference to the identity manager.
IdentityManager identityManager = awsMobileClient.getIdentityManager();

AmazonS3 s3Client = new AmazonS3Client(identityManager.getCredentialsProvider());

try{

    //This used to return TRUE but now returns FALSE
    boolean objectExists = s3Client.doesObjectExist(BUCKET_NAME, key);

    ...
//catch, etc.
因此,我无法下载对象。我假设这在某种程度上是一个与身份验证相关的问题,遵循安全原则只是告诉我对象不存在

任何一端的bucket名称或密钥都没有改变,我验证了可以通过改变以下内容来触发和解决该问题:

compile 'com.amazonaws:aws-android-sdk-s3:2.2.+' //works

以及重建/运行应用程序

我在文档中找不到任何东西,也找不到任何关于可能导致这种情况的版本更改的东西。有人知道吗?我还没有看到我能在版本中达到多高,而不会出现这个问题


编辑:2.3.9工作正常,这就是问题所在。我无法确定这些更改中的哪一个可能导致此问题。

如果您使用的是版本>=2.6.0

dependencies {
    compile ('com.amazonaws:aws-android-sdk-auth-core:2.6.0@aar') { transitive = true; }
    compile 'com.amazonaws:aws-android-sdk-core:2.6.+'
    compile 'com.amazonaws:aws-android-sdk-s3:2.6.0'
}
1创建IdentityManager的实例:

import com.amazonaws.mobile.config.AWSConfiguration;
import com.amazonaws.mobile.auth.core.IdentityManager;

IdentityManager idm = new IdentityManager(getApplicationContext(), new AWSConfiguration(getApplicationContext()));
IdentityManager.setDefaultIdentityManager(idm);
2与S3客户端一起使用

AmazonS3 s3Client = new AmazonS3Client(IdentityManager.getDefaultIdentityManager().getCredentialsProvider());

try{

    //This used to return TRUE but now returns FALSE
    boolean objectExists = s3Client.doesObjectExist(BUCKET_NAME, key);

    ...
//catch, etc.

您引用的AWSMobileClient和IdentityManager是从AWSMobileHub下载的示例应用程序的一部分吗?是。我应该提到这一点。AWSMobileClient和IdentityManager于2011年8月31日从AWS Mobile Hub示例应用程序中删除。IdentityManager作为SDK的一部分发布。您可以在aws sdk android auth core:2.6上获取它。0@aar. AWSMobileClient在aws sdk android移动客户端2.6中发布。7@aar对身份验证和登录的支持最少。您指出的示例代码无法与SDK>=2.6.0的版本一起使用。如果您想使用版本>=2.6.0,我已经添加了修复代码的答案。让我知道这对你是否有效。我会在可能的时候尝试一下。将auth-core依赖项编译为可传递的是否总是安全的?如中所示,我是否需要不这样做?因为这是一个aar文件,所以必须添加transitive=true;自动拉入依赖项。auth core的唯一依赖项是aws android sdk core。
AmazonS3 s3Client = new AmazonS3Client(IdentityManager.getDefaultIdentityManager().getCredentialsProvider());

try{

    //This used to return TRUE but now returns FALSE
    boolean objectExists = s3Client.doesObjectExist(BUCKET_NAME, key);

    ...
//catch, etc.