gpt4 book ai didi

swift - 上传到Amazon S3时如何设置权限?

转载 作者:可可西里 更新时间:2023-11-01 00:52:42 25 4
gpt4 key购买 nike

我想将上传到 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" 行时,文件被上传,但所有用户的权限设置为无。我认为问题出在上面代码的倒数第二行。当该行未被注释掉时,我收到此错误:

upload() 失败:[Error Domain=com.amazonaws.AWSS3ErrorDomain Code=0“操作无法完成。(com.amazonaws.AWSS3ErrorDomain 错误 0。)”UserInfo=0x191a5bc0 {HostId=xxx +xxxxxxx/14=, ArgumentValue=All users, Message=Argument format not recognized, ArgumentName=x-amz-grant-full-control, Code=InvalidArgument, RequestId=xxxx}]

编辑:上面的代码实际上试图授予完全控制权限,但核心问题是相同的。我还添加了一张图片,显示上传文件的权限: enter image description here

最佳答案

我找到了一个解决方案:

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 enter image description here

关于swift - 上传到Amazon S3时如何设置权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31784707/

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