question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get the image file from a preloaded image

See original GitHub issue

Is your feature request related to a problem? Please describe. I’m looking for a way to get the image file from a preloaded image, but seems Coil lacks this feature at the moment.

Describe the solution you’d like On Glide I do:

val preloadedImageFile = Glide
    .with(context)
    .downloadOnly()
    .load(imageUrl)
    .submit()
    .get()

Would be nice if we have at least one of these options in Coil:

Coil.getFile(imageUrl)

Coil.load(context, imageUrl) {
    target(object : FileTarget {
        override fun onSuccess(result: File) {
            
        }
    })
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
colinrtwhitecommented, May 11, 2022

I’ve just published 2.0.0-alpha01 which makes the disk cache public. It’s experimental and subject to change, but you can get access to the image’s file like so:

context.imageLoader.diskCache?.get(url)?.use { snapshot ->
    val imageFile = snapshot.data.toFile()
    // Read or copy the file. You **must** close the snapshot (`use` closes the snapshot)
    // or it'll prevent writing to that entry until your app is killed.
}

The new disk cache also has support for editing/removing entries. Check it out!

2reactions
saketcommented, Feb 14, 2021

+1 for this. Any chances this can be re-opened? Displaying large images through coil is a bit of a pain right now because libraries like SubsamplingScaleImageView only take in files instead of Drawables.

I tried accessing OkHttp’s cache directly, but the code is very fragile:

val coilCache = CoilUtils.createDefaultCache(context)
val file = File(coilCache.directory, "${Cache.key(imageUrl.toHttpUrl())}.1")
Read more comments on GitHub >

github_iconTop Results From Across the Web

Preloading responsive images - web.dev
Preloading dynamically-injected responsive images # · Open this example website in a new tab. · Press `Control+Shift+J` (or `Command+Option+J` on ...
Read more >
Preloading images with JavaScript - Stack Overflow
v1: Preload by passing images as arguments to preloadImages() ... Returns array of Image typed objects returned by function. Useful to check ...
Read more >
3 Ways to Preload Images with CSS, JavaScript, or Ajax
Three easy ways to preload images using either CSS, JavaScript, or Ajax - an excellent way to speed things up and boost site...
Read more >
How to Preload an Image - JavaScript - Media College
"Preloading" loads an image file into the users' computer memory so that it can be instantly accessed when needed. This is useful, for...
Read more >
A better way to preload images for web galleries
A better way to preload images for web galleries. The canonical javascript image preloader attempts to maximize the browser's ability to load resources...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found