[英]How do I upload a file into a protected s3 bucket from Swift using the s3 bucket created by AWS mobile hub?
I have an AWS mobile hub project and am attempting to upload a file into the protected folder of the autogenerated bucket. 我有一个AWS移动中心项目,正在尝试将文件上传到自动生成的存储桶的受保护文件夹中。
I am using the AWSS3TransferUtility to upload files currently after my user has authenticated. 我的用户通过身份验证后,当前正在使用AWSS3TransferUtility上传文件。 I looked at the docs and the website left inside the folders upon creation.
创建后,我查看了文件夹中的文档和网站。 They have setup the permissions to protect the data in different ways in different folders.
他们设置了权限,以不同方式保护不同文件夹中的数据。 I was able to upload files to the uploads folder with no problem.
我能够毫无问题地将文件上传到上载文件夹。 I then tried to upload to the private and protected folder and received an authorized 403 from the API call.
然后,我尝试上传到私有和受保护的文件夹,并从API调用中收到授权的403。 I checked into the permissions on the bucket through IAM.
我通过IAM检查了存储桶上的权限。
BucketName | BucketName | string like |
像 appname-userfiles-mobilehub-1213213213, ObjectPath |
appname-userfiles-mobilehub-1213213213,ObjectPath |中国 string like |
像 private/${cognito-identity.amazonaws.com:sub}/*
民营/ $ {cognito-identity.amazonaws.com:sub}/*
So I have deduced the key for upload must include the cognito-identity in the key. 因此我推断出上传的密钥必须在密钥中包含认知身份。 How do I get the current user's cognito-identity such that it will match and allow me to upload my files to S3 while ensuring their data protection integrity?
如何获得当前用户的认知身份,以使其匹配并允许我将文件上传到S3,同时确保其数据保护完整性?
I had the AWSIdentifyManager to pull the user id. 我有AWSIdentifyManager拉用户ID。
// start of upload code
let transferUtility = AWSS3TransferUtility.default()
let user = AWSIdentityManager.default().identityId
let newKey = "protected/"+user!+"/"+fileURL.lastPathComponent
transferUtility.uploadData(
data,
bucket: "appbucket-name",
key: newKey,
contentType: "text/plain",
...
//rest of code from the docs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.