swift - 使用消息“Alamofire.AFError.ResponseValidationFailureReason.unacceptableContentType”从存储中获取图像时出错
问题描述
我尝试从 Firebase 存储中获取图像,但有错误消息:
Alamofire.AFError.responseValidationFailed(原因: Alamofire.AFError.ResponseValidationFailureReason.unacceptableContentType(acceptableContentTypes: ["image/x-xbitmap", "image/jpeg", "application/octet-stream", "image/gif", "image/ ico"、"image/tiff"、"image/x-icon"、"image/bmp"、"image/x-bmp"、"image/x-win-bitmap"、"image/png"、"image/ x-ms-bmp"], responseContentType: "应用程序/json")
我可以通过浏览器下载这张图片。
我发现了同样的情况:
这些提示并没有帮助我修复我的错误。
吊舱版本:
- 阿拉莫菲尔:5.0.2
- AlamofireImage 4.0.2
最初我使用AlamofireImage : productImageView.af.setImage(withURL: url)
,但它没有用。然后我开始使用Alamofire。并在请求中传递 MIME 类型的图像/jpeg,如Content-Type:
我决定使用这种方法来修复错误,但有同样的错误,我不明白为什么(来自文档):
如果您可以在错误消息中看到我有:
响应内容类型:“应用程序/json”
那么获取图像有什么副作用吗?我做错了什么?
解决方案
链接应该是
https://firebasestorage.googleapis.com/v0/b/projectname/o/image.png?alt=media&token=auth_token
将 projectname 、 image name 和 token 替换为您的
推荐阅读
- arrays - 将对象数组的内容加载到 vuetify 组合框中
- airflow - 如何在 Google Cloud Composer 中从第三方提供商(例如 vault 或 LastPass)访问密码?
- php - 在证书上打印动态内容
- ios - 从 azure 管道构建 ipa 时,okta ionic 插件不起作用
- reactjs - 非常慢的 setState - React
- redirect - 指向 Google Workspace 侧面板中的链接
- networking - 添加随机噪声以使用 netem 发送几 Mbyte 数据
- android - 将数据传递给 Flutter 视图控制器
- javascript - CSS 最大高度转换不适用于 Javascript 类切换
- r - 使用 read_csv 导入时限制 col_type 的选项