3

I'm developing app to display the list of private images using Coil compose image loader. Coil has by default image caching enabled or we can also control caching policy for image urls which don't require credentials. How can I do image caching for private image urls. Here's my example:

 AsyncImage(
        model = ImageRequest.Builder(LocalContext.current)
            .data("${BuildConfig.BASE_URL}/.preview/avatar.jpg")
            .addHeader("Authorization", "Token something")
            .crossfade(true)
            .diskCachePolicy(CachePolicy.ENABLED)// it's the same even removing comments
            .build(),
        placeholder = painterResource(R.drawable.ic_avatar),
        contentDescription = stringResource(R.string.app_name),
        contentScale = ContentScale.Crop,
        modifier = Modifier.clip(CircleShape)
    )

However, image caching works for public image urls, if no credentials needed. If anyone has faced this issue and solve it, I would appreciate your help!

1 Answers1

1

.addHeader("Authorization", "Bearer $accessToken")

Jeffrey Liu
  • 1,063
  • 1
  • 9
  • 18