首页 > 解决方案 > 使用消息“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")

我的网址如下所示:https ://firebasestorage.googleapis.com/v0/b/####/o/executors/o4uAQa158nXTvJ5omuxqcRb0e793/products/7DDCEEAC-ED54-4910-B93D-5E40BF411B80

我可以通过浏览器下载这张图片。

我的图像具有 MIME 类型的“图像/jpeg”:在此处输入图像描述

我发现了同样的情况:

  1. 缺少响应 Content-Type 和可接受的内容类型
  2. 确保您设置了 alamofire 可接受的内容类型
  3. 图像响应序列化器

这些提示并没有帮助我修复我的错误。

吊舱版本:

最初我使用AlamofireImage : productImageView.af.setImage(withURL: url),但它没有用。然后我开始使用Alamofire。并在请求中传递 MIME 类型的图像/jpeg,如Content-Type在此处输入图像描述

我决定使用这种方法来修复错误,但有同样的错误,我不明白为什么(来自文档): 在此处输入图像描述

如果您可以在错误消息中看到我有:

响应内容类型:“应用程序/json”

那么获取图像有什么副作用吗?我做错了什么?

标签: swiftalamofirealamofireimagealamofire-request

解决方案


链接应该是

https://firebasestorage.googleapis.com/v0/b/projectname/o/image.png?alt=media&token=auth_token

将 projectname 、 image name 和 token 替换为您的


推荐阅读