我想将我上传到 S3 的文件设置为所有用户“读取”的权限,但找不到使用 AWSS3PutObjectRequest grantRead
的方法 AWSS3Permission AWSS3PermissionRead
。
有什么建议可以解决这个问题吗?
这是我的代码:
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.body = NSURL(fileURLWithPath: filePath)
uploadRequest.key = fileName
uploadRequest.bucket = S3BucketName
uploadRequest.grantFullControl = "All users" // I think here's an error
self.upload(uploadRequest)
当我注释掉 uploadRequest.grantFullControl = "All users"
行时,文件被上传,但所有用户的权限设置为“无”。我认为问题出在上面代码的倒数第二行。当该行未注释掉时,我收到此错误:
上传()失败:[错误域=com.amazonaws.AWSS3ErrorDomain代码=0“操作无法完成。(com.amazonaws.AWSS3ErrorDomain错误0。)”UserInfo=0x191a5bc0 {HostId=xxx +xxxxxxx/14=, ArgumentValue=所有用户, Message=参数格式无法识别, ArgumentName=x-amz-grant-full-control, Code=InvalidArgument, RequestId=xxxx}]
最佳答案
我找到了解决方案:
let uploadRequest = AWSS3TransferManagerUploadRequest()
uploadRequest.body = NSURL(fileURLWithPath: filePath)
uploadRequest.key = fileName
uploadRequest.bucket = S3BucketName
uploadRequest.ACL = AWSS3ObjectCannedACL.PublicRead // there was the error
self.upload(uploadRequest)
更多详情请访问:https://forums.aws.amazon.com/thread.jspa?threadID=109840
关于swift - 上传到Amazon S3时如何设置权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31784707/