gpt4 book ai didi

ios - Amazon AWS S3 从 iOS 设备上传

转载 作者:行者123 更新时间:2023-11-28 06:00:35 24 4
gpt4 key购买 nike

我一直在尝试按照他们的文档将图像/视频上传到 s3。但是,经过大量尝试后,我一直收到拒绝访问错误。

我已经为 s3:* 访问设置了一个 UnAuth 角色的认知池。但问题是我无法让它在 iOS 设备上运行。我使用 AWSTransferManager 创建上传功能,但这是我得到的响应:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>AccessDenied</Code><Message>Access Denied</Message>
<RequestId>DEE11EF134B50C8D</RequestId><HostId>/+qV8CLvPZHi4lIAHrVnKf1sDmWFcFS1dcfMX5XG0yfPG/TIASBfo/T5aGZRZg77wdn7siOrRVc=</HostId></Error>
Upload failed with error: (The operation couldn’t be completed. (com.amazonaws.AWSServiceErrorDomain error 11.))

桶政策-:

{
"Version": "2012-10-17",
"Id": "Policy1460611228663",
"Statement": [
{
"Sid": "Stmt1460611220793",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::MY_ACCOUNT_ID:root"
},
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::MY_BUCKET_NAME/*"
}
]
}

IAM UnAuth 角色策略-:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*",
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Resource": [
"*"
]
}
]
}

我卡在这了。请提出我做错了什么?

let accK = "myaccesskey"
let secretK = "mysecretkey"
let credentialsProvider = AWSStaticCredentialsProvider(accessKey: accK, secretKey: secretK)
let configuration = AWSServiceConfiguration(region: AwsRegion, credentialsProvider: credentialsProvider)
AWSS3TransferManager.register(with: configuration!, forKey: "mys3")

最佳答案

配置了身份池和 IAM 策略,以便身份池的 unauth 角色可以访问存储桶,以下代码应该可以工作

//Setup credentials
let credentialProvider = AWSCognitoCredentialsProvider(regionType: YOUR-IDENTITY-POOL-REGION, identityPoolId: "YOUR-IDENTITY-POOL-ID")

//Setup the service configuration
let configuration = AWSServiceConfiguration(region: .USEast1, credentialsProvider: credentialProvider)

//Setup the transfer utility configuration
let tuConf = AWSS3TransferUtilityConfiguration()

//Register a transfer utility object
AWSS3TransferUtility.register(
with: configuration!,
transferUtilityConfiguration: tuConf,
forKey: "transfer-utility-with-advanced-options"
)

//Look up the transfer utility object from the registry to use for your transfers.
let transferUtility = AWSS3TransferUtility.s3TransferUtility(forKey: "transfer-utility-with-advanced-options")


transferUtility.uploadData(
testData,
bucket: "BUCKET",
key: "KEY",
contentType: "video/mp4",
expression: uploadExpression,
completionHandler: uploadCompletionHandler
).continueWith (block: { (task) -> AnyObject? in
XCTAssertNil(task.error)

return nil
})

请查看我之前发布的链接以获取更多信息。

关于ios - Amazon AWS S3 从 iOS 设备上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49913691/

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