如何使用AWS移动中心创建的s3存储桶将文件从Swift上传到受保护的s3存储桶? [英] How do I upload a file into a protected s3 bucket from Swift using the s3 bucket created by AWS mobile hub?

查看:135
本文介绍了如何使用AWS移动中心创建的s3存储桶将文件从Swift上传到受保护的s3存储桶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个AWS移动中心项目,正在尝试将文件上传到自动生成的存储桶的受保护文件夹中.

I have an AWS mobile hub project and am attempting to upload a file into the protected folder of the autogenerated bucket.

  • 私人
  • 受保护的
  • 公开
  • 上传

我的用户经过身份验证后,当前正在使用AWSS3TransferUtility上传文件.创建后,我查看了文件夹中的文档和网站.他们设置了权限,以不同方式保护不同文件夹中的数据.我能够毫无问题地将文件上传到上载文件夹.然后,我尝试上传到私有和受保护的文件夹,并从API调用中收到授权的403.我通过IAM检查了存储桶上的权限.

I am using the AWSS3TransferUtility to upload files currently after my user has authenticated. 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. I checked into the permissions on the bucket through IAM.

BucketName |像|的字符串appname-userfiles-mobilehub-1213213213,ObjectPath |管理指南像|的字符串私人/$ {cognito-identity.amazonaws.com:sub}/*

BucketName | string like | appname-userfiles-mobilehub-1213213213, ObjectPath | string like | private/${cognito-identity.amazonaws.com:sub}/*

因此,我推断出上传的密钥必须在密钥中包含认知身份.如何获得当前用户的认知身份,以使其匹配并允许我将文件上传到S3,同时确保其数据保护完整性?

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?

推荐答案

我使用AWSIdentifyManager提取用户ID.

I had the AWSIdentifyManager to pull the user 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

这篇关于如何使用AWS移动中心创建的s3存储桶将文件从Swift上传到受保护的s3存储桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆