Does anyone know if it's possible to get the image...
# android
c
Does anyone know if it's possible to get the image size from coil image loader? After loading my image I want to show a toast with the size in KB or MB.
c
That isn’t possible in Coil’s API, but you could probably declare an OkHttp interceptor that shows a toast with the request body size: https://square.github.io/okhttp/interceptors/#interceptors
Also here’s how to set a custom OkHttp client on your ImageLoader instance: https://coil-kt.github.io/coil/recipes/#using-a-custom-okhttpclient
c
Thanks. That's helpful!
@Colin White is there any benefit to setting a custom okhttp client if you don't need any customizations on the client itself?
c
If you already have an OkHttpClient instance (say, for Retrofit) you can create a new instance using
newBuilder
and pass it to your ImageLoader. This will let your ImageLoader share connections + threads with Retrofit and save some memory: https://square.github.io/okhttp/4.x/okhttp/okhttp3/-ok-http-client/#okhttpclients-should-be-shared