gpt4 book ai didi

ios - 使用 AWS SDK 2 和 Cognito 为使用 iOS SDK 2 的未授权用户将文件放在 S3 上

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:14:49 26 4
gpt4 key购买 nike

我想将文件上传到我的 S3 存储桶之一。

在我的应用中我有:

在我的应用委托(delegate)中

let credentialProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "us-east-1:05da3124-9aab-abd9-081231a31")
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

一个上传函数

func uploadFile(fileURL: NSURL, type: MediaType) {
var uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.body = fileURL
uploadRequest.key = fileURL.lastPathComponent
uploadRequest.bucket = "xxx.xxx.dev"
transferManager.upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in
if let error = task.error {
log.debug("Upload failed with error: \(error)")
} else {
log.debug("Object \(uploadRequest.key) uploaded with \(task.result)")
XXXRESTManager.sharedInstance.doRegisterUpload(uploadRequest.key, type: type)
}
return nil
}
}

附加到我的身份池中未经身份验证的角色的策略:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3: PutObject"
],
"Resource": "arn:aws:s3:::xxx.xxx.dev"
},
{
"Effect": "Allow",
"Action": [
"sns:CreatePlatformEndpoint",
"sns:Subscribe"
],
"Resource": [
"*"
]
}
]
}

与 cognito 的连接是正确的(我现在在 AWS 控制台中有一个未经身份验证的用户。

但是,当我尝试上传文件时,权限仍然被拒绝。我错过了什么?

最佳答案

AWSS3TransferManagerUploadRequest 可能需要比 PutObject 更多的权限才能工作。您是否尝试过根据您的政策为 S3 授予更广泛的权限?可能它至少需要 GetObject,但首先尝试使用 "Action": "s3:*" 这样我们就可以确定问题出在那个部分。

关于ios - 使用 AWS SDK 2 和 Cognito 为使用 iOS SDK 2 的未授权用户将文件放在 S3 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30921173/

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