Seb*_*ger 9 amazon-s3 amazon-web-services ios swift
我正面临着AWSS3的一个奇怪问题.
建立:
- > Cognito,Dynamo甚至S3(通过cognito用户数据)工作.
但是我现在尝试使用以下代码直接连接到AWS3:"
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
})
Run Code Online (Sandbox Code Playgroud)
并得到错误:
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.'
Run Code Online (Sandbox Code Playgroud)
我正在使用从AWS Mobiel HUB下载的plist配置,因此它有点惊讶它不起作用(正如所有其他组件那样).
任何想法可能是什么问题?plist实际上包含桶ID和区域.
Fra*_*eau 12
对我来说,在上传之前,我必须使用以下代码配置凭据:
let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1,identityPoolId:PoolID)
let configuration = AWSServiceConfiguration(region:.USEast1, credentialsProvider:credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
Run Code Online (Sandbox Code Playgroud)
其中PoolID是我的Cognito身份.我希望这有助于其他人.
| 归档时间: |
|
| 查看次数: |
7803 次 |
| 最近记录: |