Custom HttpClientHandler for images in Xamarin Forms

125 Views Asked by At

I get a list of urls of images (e.g., https://thisisanurl.png) from a let's say API/GetImageUrls. But those url images can't be viewed without a key authentification.

I was using FFImageLoading plugin to add a custom HttpClient to the ImageService for opening those urls and get the images behind it.

public App()
    {
        ImageService.Instance.Initialize(new Configuration
        {
            HttpClient = new HttpClient(new CustomHttpClientHandler()),
            VerboseLogging = true
        });

        InitializeComponent();
    }

...

public class CustomHttpClientHandler : HttpClientHandler
{

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        request.Headers.Add("APIKey", AppSettings.ApiKey);
        return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
    }

}

Now that FFImageLoading isn't supported anymore I need a new way of doing this. Any ideas?

Thanks

0

There are 0 best solutions below