我目前在我的应用程序中使用 Mobile Hub。当我尝试使用 S3 将照片上传到我的存储桶时,我逐字复制了此处文档中的功能以下载/上传文件:https ://docs.aws.amazon.com/aws-mobile/latest/developerguide/add- aws-mobile-user-data-storage.html
这是我在 Swift 中尝试使用 S3TransferUtility 的代码:
func uploadData(data: Data, fileName: String) {
let expression = AWSS3TransferUtilityUploadExpression()
expression.progressBlock = {(task, progress) in
DispatchQueue.main.async(execute: {
// Do something e.g. Update a progress bar.
})
}
var completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock?
completionHandler = { (task, error) -> Void in
DispatchQueue.main.async(execute: {
// Do something e.g. Alert a user for transfer completion.
// On failed uploads, `error` contains the error object.
})
}
let transferUtility = AWSS3TransferUtility.default()
transferUtility.uploadData(data,
bucket: "my bucket name",
key: fileName,
contentType: "image/jpeg",
expression: expression,
completionHandler: completionHandler).continueWith {
(task) -> AnyObject? in
if let error = task.error {
print("Error: \(error.localizedDescription)")
}
if let res = task.result {
// Do something with uploadTask.
print(res)
}
return nil
}
}
我在控制台中收到此错误:控制台 中的错误图像
我调查了 AWS S3 和提供的 awsconfiguration.json 文件,一切似乎都井井有条:
我项目中的 AWSConfiguration.json 文件
现在我很困惑,因为我认为 Mobile Hub 应该负责 IAM 配置,而不是处理所有事情。
有人可以指出我正确的方向来解决这个问题吗?谢谢你。