swiftalamofirealamofireimagealamofire-request

Error fetch image from storage with message 'Alamofire.AFError.ResponseValidationFailureReason.unacceptableContentType'


I attemp to fetch image from Firebase storage, but have error message:

Alamofire.AFError.responseValidationFailed(reason: 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: "application/json")

My url looks like this: https://firebasestorage.googleapis.com/v0/b/####/o/executors/o4uAQa158nXTvJ5omuxqcRb0e793/products/7DDCEEAC-ED54-4910-B93D-5E40BF411B80

I can download this image via browser.

My image has MIME-type 'image/jpeg':enter image description here

I found the same situation:

  1. Response Content-Type was missing and acceptable content types
  2. Make sure you set alamofire acceptable content types
  3. Image Response Serializers

These hints didn't help me to fix my bug.

Version of pod:

Initially I used AlamofireImage: productImageView.af.setImage(withURL: url), but it didn't work. Then I began using Alamofire. And into request I pass MIME-type image/jpeg like Content-Type: enter image description here

And I decided to use this approach to fix bug, but has the same error and I don't understand why(from docs): enter image description here

If you can see in error-message I have:

responseContentType: "application/json"

So does it have any side effect to fetch image? What I do wrong at all?


Solution

  • Link should be

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

    replace projectname , image name and token to yours