使用凭据的 Coil 组合图像缓存

3

我正在开发一个应用程序,使用Coil compose图像加载器来显示私有图像列表。Coil默认启用图像缓存,或者我们也可以控制不需要凭据的图像URL的缓存策略。如何为私有图像URL进行图像缓存。以下是我的示例:

 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)
    )

然而,如果不需要凭证,图像缓存适用于公共图像url。如果有人遇到这个问题并解决了它,我将非常感激你的帮助!


你找到解决方案了吗? - Jeffrey Liu
1个回答

1

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

可以翻译为“添加头部信息:Authorization,值为Bearer加上访问令牌($accessToken)”。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接