-
Notifications
You must be signed in to change notification settings - Fork 637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Coil 3] Local image files don't show on PC #2014
Comments
What's the exception stacktrace from |
@colinrtwhite The exception stacktrace is the following:
|
@colinrtwhite After updating to version
|
Looks like this has nothing to do with the coil library. |
@devmike01 This doesn't work, I got another exception -
|
@alekseyHunter I agree with @devmike01 I think there might be something wrong with your path, though I'm not sure exactly how to represent a Windows drive name in an Okio path. I'd try: There might also be issues with Coil relying on |
@colinrtwhite This doesn't work either
|
@alekseyHunter Fix your error or post the issue on StackOverflow. Try accessing this image( |
@devmike01 What's the logic? How to fix the error, if there is an error in the library.
@devmike01 Can you load a local picture on your computer using the library? Will you show the result on video?
@devmike01 Everything loads fine. |
I meant web browser, not your image browser. |
@devmike01 Yes, the second screenshot shows the result in the web browser (pixlr.com). Everything works in it ;) |
The second images is hosted on a server. I meant load the photo from your folder path in your web browser. |
I just had the same issue, it's nice to know that it wasn't me. I'm using 3.0.0-Alpha 04. When passing in a I had to do this to get it to work: val loc = "file://" + imgFiles[1].absolutePath.replace("\\", "/")
AsyncImage(
model = loc, contentDescription = "Test Photo"
) I would assume that we should expect to just pass a File object to Coil, and it would work correctly, right? It definitely does not seem to like Windows file paths. |
While the above temporary fix does work on my C drive, it also does not work when referencing a file on another drive. |
I run into the exact same problem. I am on The file I want to show on Windows is located at When I run File("C:/Users/<user>/AppData/Roaming/<project>/Thumbnails/tool2019fearinoculum.jpg").exists() or File("C:\\Users\\<user>\\AppData\\Roaming\\<project>\\Thumbnails\\tool2019fearinoculum.jpg").exists() it returns AsyncImage(
model = File("C:/Users/<user>/AppData/Roaming/<project>/Thumbnails/tool2019fearinoculum.jpg"),
contentDescription = "null",
onError = { println(it) }
) it gives me I agree with @ejektaflex. If I am not doing anything completely wrong, I would also assume this code to work. Edit: |
Same here. Compose for Desktop in a Windows 11 machine.
This shows nothing in my UI, but outputs the following error:
I'm positive the file is OK, because I'm scanning a folder, and I'm migrating from another image loader that displayed it with no problem. Also, if I pass an URL of a remote image, it loads and displays perfectly fine. |
This workaround is fine in my Windows, but I suppose it will break anywhere else.
|
Would you mind posting the exact contents of the String that you passed to AsyncImage? My images are located in C:...\AppData\ and I tried all possibilities with |
Of course, this is the original file: |
Thank you. What exactly is .myapp? Is it the root directory of your app? I was looking for a workaround where I can load images from the "AppData" folder on the C: drive. Any ideas? Because using the absolute path with the drive letter seems to create the confusion within Coil. |
I also tried it with Okio itself: FileSystem.SYSTEM.exists("C:/Users/<user>/AppData/Roaming/<project>/Thumbnails/tool2019fearinoculum.jpg".toPath()) returns AsyncImage(
model = "C:/Users/<user>/AppData/Roaming/<project>/Thumbnails/tool2019fearinoculum.jpg".toPath(),
contentDescription = "null",
onError = { println(it) }
) it throws |
It's just a subfolder of the working directory of my app, nothing special. |
I have the same issue on Windows. Using workaround below works on C drive only, not on other drive letters.
I think the issue is in FileUriFetcher.kt in Coil. It has this code:
For example input file on drive D "file://D:/861746.jpg" the resulting path in this code becomes "/861768.jpg", thus the files location cannot be resolved. It works for C drive, because that is the default drive. The solution is the above code should take drive letter into consideration. EDIT: |
Possible workaround to use normal windows path. Create a custom fetcher: internal class WindowsFileUriFetcher(
private val uri: Uri,
private val options: Options,
) : Fetcher {
@OptIn(InternalCoilApi::class)
override suspend fun fetch(): FetchResult {
val path = uri.toString().toPath()
return SourceFetchResult(
source = ImageSource(path, options.fileSystem),
mimeType = MimeTypeMap.getMimeTypeFromExtension(path.name.substringAfterLast('.', "")),
dataSource = DataSource.DISK,
)
}
class Factory : Fetcher.Factory<Uri> {
private val regex = "^[a-zA-Z]:\\\\.*".toRegex()
override fun create(
data: Uri,
options: Options,
imageLoader: ImageLoader,
): Fetcher? {
if (hostOs != OS.Windows || !regex.matches(data.toString())) return null
return WindowsFileUriFetcher(data, options)
}
}
} Register it: ImageLoader.Builder(context)
.components {
add(OkHttpNetworkFetcherFactory())
add(WindowsFileUriFetcher.Factory())
}
.build()
|
Is this still happening? Do you need any help creating a patch here? |
Describe the bug
Hello!
Local image files don't show on PC.
Error type is not in the function
error()
To Reproduce
Logs/Screenshots
Version
Coil 3.0.0-alpha01
kotlin.version=1.9.21
agp.version=8.1.4
compose.version=1.5.11
The text was updated successfully, but these errors were encountered: