ios - Amplify 无法从 s3 下载对象
问题描述
我正在尝试使用 amplify-swift 将现有 s3 存储桶中的对象下载到 IOS 应用程序。我已经按照教程初始化放大和导入存储。我正在尝试调用未经身份验证的用户-> 在 Cognito 控制台中,我为 unauth 用户定义了一个角色(并允许访问 unauth 用户),授予他对我的存储桶的权限并使用模拟器验证 getObject 是否有效。调用此代码时:
let key = "images/some_file.txt"
do {
try Amplify.add(plugin: AWSCognitoAuthPlugin())
try Amplify.add(plugin: AWSS3StoragePlugin())
try Amplify.configure()
print("Amplify configured with storage plugin")
} catch {
print("Failed to initialize Amplify with \(error)")
}
Amplify.Storage.downloadData(
key: key,
progressListener: { progress in
print("Progress: \(progress)")
}, resultListener: { (event) in
switch event {
case let .success(data):
print("Completed: \(data)")
case let .failure(storageError):
print("Failed: \(storageError.errorDescription). \(storageError.recoverySuggestion)")
}
})
我收到此错误:
Amplify 配置了存储插件 2021-03-31 18:09:09.988304+0300 ota[30840:728969] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed Progress: <NSProgress: 0x6000001d50e0> : Parent: 0x0 (portion: 0) / Fraction completed: /已完成:-1
的 243 失败:HTTP 响应状态代码为 [403].. TODO 一些状态代码以恢复消息映射器。有关 HTTP 状态代码的更多信息,请查看https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
我检查了池 ID、存储桶名称是否在 json 文件中都正确定义。我错过了什么?
编辑:
这似乎可行,所以我知道实际问题不在于权限,而在于放大默认下载:
let expression = AWSS3TransferUtilityDownloadExpression()
expression.progressBlock = {(task, progress) in DispatchQueue.main.async(execute: {
print("Downloading...")
})
}
let credentialProvider = AWSCognitoCredentialsProvider(regionType: .EUWest1, identityPoolId: "eu-west-1:xxxxxx")
let configuration = AWSServiceConfiguration(region: .EUWest1, credentialsProvider: credentialProvider)
AWSS3TransferUtility.register(with: configuration!, forKey: "customTU")
let tu = AWSS3TransferUtility.s3TransferUtility(forKey: "customTU")
tu?.downloadData(fromBucket: bucket, key: _key, expression: expression) { (task, URL, data, error) in
if error != nil {
print(error!)
}
DispatchQueue.main.async(execute: {
print("Got here")
let rawJSON = (String(data: data!, encoding: .utf8))!
print(rawJSON)
})
}
解决方案
推荐阅读
- dicom - 如何使用 HL7 消息在 DCM4CHE 中为患者创建模态工作列表?
- rest - 使用 vcsim 模拟器调用 vCenter 6.5 REST API
- windows - 在 TD Agent Admin Prompt 上运行命令
- methods - 抽象方法不指定主体 - 接口试图实现超级接口方法,在 JDK 8 中给出编译时错误
- javascript - 每次在 React 中调用事件处理程序时如何重置 react-id-swiper?
- java - 使用多字符分隔符拆分正则表达式
- javascript - pushState 问题 Framework7 v3.5.2 不加载视图
- mysql - Kubernetes mysql 8.0.13 未从 ENV 正确初始化
- javascript - 隐形 reCaptcha:无法进行有效的 AJAX 调用,出现无限循环
- python - Pandas 多列 groupby 绘图以在 x 轴上显示第一级组