I'm uploading a file to my S3 bucket, and I want it to have public read permission. It seems like it should be simple, but like many things in my life, it is not. Looking for answers, the closest hint I've found is:
Add a header to your PUT request: x-amz-acl: public-read
which seems simple enough, but I'm using AWSS3TransferUtitlity, not PUT, and trying to set the requestHeader on the AWSS3TransferUtilityUploadExpression fails - setValue: forRequestHeader: is not recognized so I'm using requestParamaters instead, but that doesn't work either. I've searched and read till my eyes are bleary. Can someone help, please?
My code so far:
AWSS3TransferUtilityUploadExpression *expression = [AWSS3TransferUtilityUploadExpression new];
// expression.uploadProgress = self.uploadProgress;
[expression.requestParameters setValue:@"public-read" forKey:@"x-amz-acl"];
AWSTask *atask;
AWSS3TransferUtility *transferUtility = [AWSS3TransferUtility defaultS3TransferUtility];
NSLog(@"started file trans: %@", self.fileToSend.fileURL);
[atask = [transferUtility uploadFile:self.fileToSend.fileURL
bucket:S3BucketName
key:self.fileToSend.fileName
contentType:self.fileToSend.mimeType
expression:expression
completionHander:self.completionHandler]
continueWithBlock:^id(AWSTask *task) {
EDIT:
Some progress. I found I was using an outdated version of the SDK and uptodate version of the documentation. Another dumb mistake. Anyway, after updating the SDK and recompiling, it runs, but creates and exception 'NSUnknownKeyException', reason: '[<__NSDictionary0 0x12ed0c280> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key x-amz-acl.'
EDIT: OK. Fixed. With combination of hints, a step back, I changed my request header line to :
[expression setValue:@"public-read" forRequestHeader:@"x-amz-acl"];
Thanks to the responders.
In swift use like this,
let expression = AWSS3TransferUtilityUploadExpression()
expression.setValue("public-read", forRequestHeader:"x-amz-acl")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With