Skip to content

Instantly share code, notes, and snippets.

@KatieBarnett
Last active January 13, 2025 22:29
Show Gist options
  • Select an option

  • Save KatieBarnett/12e07bb59fae810b850b4f741fbdcf4a to your computer and use it in GitHub Desktop.

Select an option

Save KatieBarnett/12e07bb59fae810b850b4f741fbdcf4a to your computer and use it in GitHub Desktop.
Downloading an image to a file in a Coroutine Worker - Part 2
private suspend fun downloadImage(...): String {
...
// Get the path of the loaded image from DiskCache.
val path = context.imageLoader.diskCache?.openSnapshot(url)?.use { snapshot ->
val imageFile = snapshot.data.toFile()
// Use the FileProvider to create a content URI
val contentUri = getUriForFile(
context,
"${applicationContext.packageName}.provider",
imageFile,
)
// return the path
contentUri.toString()
}
return requireNotNull(path) {
"Couldn't find cached file"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment