2
votes

I'd like to set permissions for the files I'm uploading to S3 to be "Read" for All users, but can't find the way to use AWSS3PutObjectRequest grantRead neither AWSS3Permission AWSS3PermissionRead.

Any suggestion how to solve the problem?

Here's my code:

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)

When I comment out the line uploadRequest.grantFullControl = "All users" the file gets uploaded, but the privilege for All users is set to None. I think the problem is in the penultimate line in the above code. When the line is not commented out I get this error:

upload() failed: [Error Domain=com.amazonaws.AWSS3ErrorDomain Code=0 "The operation couldn’t be completed. (com.amazonaws.AWSS3ErrorDomain error 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}]

EDIT: The code above actually tries to grant full control permissions but the core problem is the same. Also I've added an image showing privileges for uploaded file: enter image description here

1

1 Answers

4
votes

I've found a solution:

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)

More details at: https://forums.aws.amazon.com/thread.jspa?threadID=109840 enter image description here