Alamofire / AlamofireImage

AlamofireImage is an image component library for Alamofire
MIT License
3.99k stars 523 forks source link

Response Content-Type "text/plain" does not match any acceptable types #454

Closed nick70007 closed 2 years ago

nick70007 commented 2 years ago

In mY swiftUI App i am trying to download image with POST request abd that post request contains "text/plain" type as output and i am getting this error:

Couldn't downloaded image: Response Content-Type "text/plain" does not match any acceptable types: image/jp2,image/bmp,application/octet-stream,image/x-icon,image/heic,image/x-bmp,image/heif,image/x-xbitmap,image/webp,image/x-win-bitmap,image/jpg,image/gif,image/png,image/ico,image/jpeg,image/tiff,image/x-ms-bmp.

The url i am trying to download:- https://ipfs.infura.io:5001/api/v0/block/cat?arg=QmcrJRMrFnGGHtC4bwkDYsnqaG9fmGSV6qHATa9h6j3jxi

My code Snippet:

      AF.request(urlString, method: .post).responseImage { response in
          debugPrint(response)
          debugPrint(response.result)

        if case .success(let downloadedImage) = response.result {
            print("Image downloaded: \(downloadedImage)")

            DispatchQueue.main.async {
                self.imageCache.set(forKey: self.urlString!, image: downloadedImage)
                self.image = downloadedImage
            }
        } else if case .failure(let error) = response.result {
            print("Couldn't downloaded image: \(error.localizedDescription)")
        }
    }
jshier commented 2 years ago

This is most likely an authorization or other error that returning a plain text response rather than the image. You'll want to investigate how to properly make an authenticated request to that API.