我正在将一个文件上传到我的S3桶中,我希望它具有公共读取权限。它似乎应该是简单的,但就像我生活中的许多事情一样,它不是。为了寻找答案,我发现的最接近的提示是:
在PUT请求中添加一个标题:x acl: public-read
这似乎很简单,但我使用的是AWSS3TransferUtitlity,而不是PUT,并且尝试在AWSS3TransferUtilityUploadExpression上设置requestHeader失败-- setValue: forRequestHeader:不被识别,所以我使用requestParamaters,但这也不起作用。我一直在寻找和阅读,直到我的眼睛变得昏暗。有人能帮忙吗?
到目前为止我的代码是:
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) {编辑:一些进展。我发现我使用的是一个过时的SDK版本和最新版本的文档。又一个愚蠢的错误。无论如何,在更新SDK并重新编译之后,它将运行,但是创建和异常'NSUnknownKeyException',原因:'[<__NSDictionary0 0x12ed0c280> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key x-amz-acl.'
编辑:好的。已修复。通过组合提示,退一步,我将请求标题行更改为:
[expression setValue:@"public-read" forRequestHeader:@"x-amz-acl"];多亏了救援队。
发布于 2020-05-12 10:29:25
像这样迅速地使用,
let expression = AWSS3TransferUtilityUploadExpression()
expression.setValue("public-read", forRequestHeader:"x-amz-acl")https://stackoverflow.com/questions/37740406
复制相似问题