![](/img/trans.png)
[英]Switch from unauth to developer authenticated cognito user - AWS iOS SDK
[英]Put file on S3 with AWS SDK 2 & Cognito for unauth users using iOS SDK 2
我想將文件上傳到我的 S3 存儲桶之一。
在我的應用程序中,我有:
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:*"
以便我們可以確保問題出在該部分。
我不知道是什么導致了這個問題,但我設法讓它起作用。 問題中的代碼是正確的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.