Ben*_*low 8 objective-c amazon-s3 ios
我正在将文件上传到我的 S3 存储桶,并且希望它具有公共读取权限。看起来应该很简单,但就像我生活中的许多事情一样,事实并非如此。寻找答案,我发现的最接近的提示是:
向 PUT 请求添加标头:x-amz-acl: public-read
这看起来很简单,但我使用的是 AWSS3TransferUtility,而不是 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) {
Run Code Online (Sandbox Code Playgroud)
编辑:一些进展。我发现我使用的是过时版本的 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"];
Run Code Online (Sandbox Code Playgroud)
感谢各位回复者。
像这样快速使用,
let expression = AWSS3TransferUtilityUploadExpression()
expression.setValue("public-read", forRequestHeader:"x-amz-acl")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1973 次 |
| 最近记录: |