ListCollections is not listing correct collections in Android App - AWS Rekognition

白昼怎懂夜的黑 提交于 2019-12-24 21:12:25

问题


Ok so I have been stuck here for about more than a week now and I know its some dumb mistake. Just can't figure it out. I am working on a project that is available of two platforms, Android & iOS. Its sort of a facial recognition app. When I try to create/access collections from iOS application and python script, they both access the same collection from my AWS account.

But when I try to access from Android application, it creates/accesses it's own collections. The collections created by Android app are neither accessible anywhere other than this Android app nor this android app can access collections created by iOS app or python script.

I have tried listing collections on all these three platforms. iOS and Python list exact same collections while the collections listed by Android app are the ones created by an android app only.

Here is the code I am using to list collections on android:

        mCredentialsProvider = new CognitoCachingCredentialsProvider(
                mContext.getApplicationContext(),
                "us-east-2:4xbx0x6x-9xbx-xax7-x9xf-x5x0xexfx1xb", // Identity pool ID
                Regions.US_EAST_2 // Region
        );

        mAmazonRekognitionClient = new AmazonRekognitionClient(mCredentialsProvider);

        ListCollectionsResult listCollectionsResult = mAmazonRekognitionClient.listCollections(new ListCollectionsRequest().withMaxResults(20));
        Log.i(TAG, listCollectionsResult.getCollectionIds().toString());

This is the log result:

[i_facesbxyxuxqxbxvxlxwx6x7xex5xmxfx, i_facestxnxaxoxoxqxaxwx4xtxuxwxoxrx, root_faces_data]

This is the python code I using to list collections:

import boto3
client = boto3.client('rekognition')
response = client.list_collections()
print(response['CollectionIds'])

This is the result:

['i_facesbxyxuxqxbxvxlxwx6x7xex5xmxfx', 'root_faces_data']

That's it. Nothing else. Just this code. You can see that one is showing 3 collections while other is showing two. I am using the exact same region and identity pool ID in iOS app and it's listing same collections as in python. The reason I think iOS app is fine because the collections listed by both iOS and python are same. Is there anything I need to change? Is there any additional setup I need to do to make it work? Please let me know. Thanks.


回答1:


So like most of the time, I saved myself. Turns out when we pass cognito credentials to Rekognition client in Android, it does not use the same region as that of Cognito. So we have to explicitly set region of Rekognition client as well. Like this:

mAmazonRekognitionClient.setRegion(Region.getRegion(Regions.US_EAST_2));

And that's all.



来源:https://stackoverflow.com/questions/53117918/listcollections-is-not-listing-correct-collections-in-android-app-aws-rekognit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!