Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download images via AlamofireImage framework with Content-Type: 'binary/octet-stream'

I try to download images from Amazon S3 server via AlamofireImage framework.

The Images on the S3 server, save with 'Content-Type' = 'binary/octet-stream'.

In the beginning I got the Error:

Failed to validate response due to unacceptable content type.

So, I tried to change/update the HTTP Header's request in order to support with binary/octet-stream'

I updated the method:

private func URLRequestWithURL(URL: NSURL) -> NSURLRequest 

In the UIImageView+AlamofireImage.swift file to:

private func URLRequestWithURL(URL: NSURL) -> NSURLRequest {
    let mutableURLRequest = NSMutableURLRequest(URL: URL)
    mutableURLRequest.addValue("binary/octet-stream", forHTTPHeaderField: "Content-Type")
    return mutableURLRequest
}

And is still not working, Just after I added the:

let contentTypes: Set<String> = ["Content-Type", "binary/octet-stream"]
Request.addAcceptableImageContentTypes(contentTypes)

The problem was solved, But I really don't like the fact that I changed a private method in the AlamofireImage framework.

I wonder if there is an elegant way to solve this problem, given I can't change the images 'Content-Type' in the S3 server.

Thanks

like image 512
Guy Kahlon Avatar asked Oct 16 '25 18:10

Guy Kahlon


1 Answers

Doing Request.addAcceptableImageContentTypes(["binary/octet-stream"]) should be all that you need to get it to work.

If you were using af_setImageWithURL, there was a bug that it wasn't using the acceptableImageContentTypes. AlamofireImage 2.2.0 fixes that.

like image 192
brussell Avatar answered Oct 18 '25 11:10

brussell