Hello, I want to load an image in jetpack compose,...
# compose
e
Hello, I want to load an image in jetpack compose, but the url redirects me to the image that's how the backend wants it, how can i achieve it using Coil library. So the url in the AsyncImage will redirect me to the image.
c
Do you have an example of the URL?
e
my url will redirect to a temporary url using amazon s3
c
I think that should work fine. Coil just uses okhttp under the hood to follow redirects and fetch the image IIRC
e
the thing is if I print the image, in the logs I click on the url and it redirects me
but coil is not
c
did you try enabling logging in coil to see if it gives you any helpful error messages?
e
no i did not
Copy code
@Composable
fun PatientImagesView(model: String, onClick: () -> Unit) {
    AsyncImage(
        model = ImageRequest.Builder(LocalContext.current)
            .data(model)
            .build(),
        contentDescription = "attached image",
        contentScale = ContentScale.Crop,
        modifier = Modifier
            .size(60.dp)
            .clickable { onClick() })
}
j
Does S3 using some kind of auth headers maybe? In that case maybe need to add headers into ImageLoader or ImageRequest.
e
Copy code
val imageLoader = LocalContext.current.imageLoader.newBuilder()
        .logger(DebugLogger())
        .build()
    AsyncImage(
        model = ImageRequest.Builder(LocalContext.current)
            .data(model)
            .build(),
        imageLoader = imageLoader,
        contentDescription = "attached image",
        contentScale = ContentScale.Crop,
        modifier = Modifier
            .size(60.dp)
            .clickable { onClick() })
}
i did not face any issue
but sill not loading
j
Could it be related to this? https://github.com/coil-kt/coil/issues/1699
y
If you really need to, say the response is literally a string with a new url to fetch, then you can always do this with a custom OkHttp Interceptor. I'd suggest making a request in a test program just using OkHttpClient and see you are getting the right result (bytes, content-length, content-type etc)
c
what is the output of the debug logger?
does it say success? or give you any failures
348 Views