gpt4 book ai didi

ios - AWS : DeveloperAuthenticatedIdentityProvider not firing IOS Swift

转载 作者:搜寻专家 更新时间:2023-10-31 08:22:01 27 4
gpt4 key购买 nike

我正在尝试集成 S3 上传以上传视频文件,并尝试了 Developer authenticated Identity 方法。一切都按照 aws docs 配置说。

DeveloperAuthenticatedIdentityProvider 类:

class DeveloperAuthenticatedIdentityProvider : AWSCognitoCredentialsProviderHelper {
override func token() -> AWSTask<NSString> {
//return AWSTask //with token and will set identityId
}

然后

let devAuth = DeveloperAuthenticatedIdentityProvider(regionType: COGNITO_REGION, identityPoolId: COGNITO_POOL_ID, useEnhancedFlow: true, identityProviderManager:nil)
let credentialsProvider =
AWSCognitoCredentialsProvider(regionType: COGNITO_REGION, identityProvider:devAuth)

let configuration =
AWSServiceConfiguration(region: S3_REGION, credentialsProvider:credentialsProvider)

AWSServiceManager.default().defaultServiceConfiguration = configuration

配置这些东西后尝试使用 AWSS3TransferManager 上传

let transferManager = AWSS3TransferManager.default()

let uploadingFileURL = URL(fileURLWithPath: "your/file/path/myTestFile.txt")

let uploadRequest = AWSS3TransferManagerUploadRequest()

uploadRequest.bucket = "myBucket"
uploadRequest.key = "myTestFile.txt"
uploadRequest.body = uploadingFileURL
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
})

每当我调用 Upload 方法时它都会显示

[Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=8"(null)" UserInfo={__type=NotAuthorizedException,message=Unauthenticated access is not supported for this identitypool.}]

DeveloperAuthenticatedIdentityProvider 也没有被解雇

请帮忙。

最佳答案

当您将开发人员身份验证身份用于 Cognito 身份提供者时,您无需使用 AWSS3TransferManager.default()您需要使用 key 将 AWSServiceConfiguration 注册到 AWSS3TransferManager

AWSS3TransferManager.register(with: configuration!, forKey: "KEY")

试试这个方法:

let devAuth = DeveloperAuthenticatedIdentityProvider(regionType:  COGNITO_REGION, identityPoolId: COGNITO_POOL_ID, useEnhancedFlow: true, identityProviderManager:nil)
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: COGNITO_REGION, identityProvider:devAuth)
let configuration = AWSServiceConfiguration(region: S3_REGION, credentialsProvider:credentialsProvider)

AWSS3TransferManager.register(with: configuration!, forKey: "YOUR_KEY")

//Start Upload

let uploadRequest = AWSS3TransferManagerUploadRequest()

//Set all properties to uploadRequest

AWSS3TransferManager.s3TransferManager(forKey: "YOUR_KEY").upload(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block: { (task:AWSTask<AnyObject>) -> Any? in
// Do something with the response

if task.isCancelled {
print("Cancelled Upload")

}
else if (task.error != nil) {

print("Upload error --> \(task.error)")
}else{

print("Upload success!!! Be happy :)")

}
return task
})

试一试,我想它可能有用。

关于ios - AWS : DeveloperAuthenticatedIdentityProvider not firing IOS Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47811311/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com