Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

ios - AWSS3 Region / plist configuration issue 'The service configuration is `nil`

I am facing a strange issue with AWSS3.

Setup:

  • AWS Mobile HUB
  • Cognito
  • DynamoDB
  • S3

--> Cognito, Dynamo & even S3 (through cognito user data) work.

However I now tried to connect directly to AWS3 with the following code:"

let transferManager = AWSS3TransferManager.default()
                            let uploadRequest = AWSS3TransferManagerUploadRequest()
                            uploadRequest?.bucket = "XXXXXXXXXXXX"
                            uploadRequest?.key = "user-data/" + awsId! + "/primary_profile_picture.png"
                            uploadRequest?.body = imgUrl as URL

                            transferManager.upload(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask<AnyObject>) -> Any? in

                                if let error = task.error as? NSError {
                                    if error.domain == AWSS3TransferManagerErrorDomain, let code = AWSS3TransferManagerErrorType(rawValue: error.code) {
                                        switch code {
                                        case .cancelled, .paused:
                                            break
                                        default:
                                            print("Error uploading: (uploadRequest?.key) Error: (error)")
                                        }
                                    } else {
                                        print("Error uploading: (uploadRequest?.key) Error: (error)")
                                    }
                                    return nil
                                }

                                let uploadOutput = task.result
                                print("Upload complete for: (uploadRequest?.key)")
                                return nil
                            })

and am getting the error:

AWSiOSSDK v2.5.1 [Debug] AWSInfo.m line:122 | -[AWSServiceInfo initWithInfoDictionary:checkRegion:] | Couldn't read the region configuration from Info.plist for the client. Please check your `Info.plist` if you are providing the SDK configuration values through `Info.plist`.
2017-02-20 19:29:21.748997 [2210:1152801] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method.'

I am using the downloaded plist configuration from AWS Mobiel HUB and am therfore a bit surprised that it does not work (as all other components do).

Any ideas what the issue might be? The plist actually contains the bucket ID & region.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For me, I had to configure the credentials with the following code, before uploading:

let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1,identityPoolId:PoolID)
let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = configuration

Where PoolID is my Cognito identity. I hope this helps others.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...