Open eskatos opened 8 months ago
that's java URI syntax right?
So the better way to do it would be either to write your own string mapper and use it in your KamelConfig:
Or.. the default common string mapper could be modified in the library and split into expect actual definitions, and extended to add uri support on jvm. Or is the java uri format useful on other targets as well? In that case the default common string mapper could be extended for other targets too.
Lmk what you think
Also fyi if you did instead asyncPainterResource(URI("file://path/to/image.png"))
it should work as is.
The file
URI scheme is not specific to the JVM https://datatracker.ietf.org/doc/html/rfc8089
There's no URI
type in Kotlin common so asyncPainterResource(URI("file://path/to/image.png"))
doesn't work.
I'll give the custom mapper way a try.
Thanks for the reference.
io.kamel.core.utils.URI
technically has the same constructor for all targets.. so I could add a way to create one in common if that is desired
Using asyncPainterResource(io.kamel.core.utils.URI("file://path/to/image.png"))
in my JVM actual
doesn't load the image. I'll stick with my "dirty" workaround for now that basically does this on the JVM:
when {
url.startsWith("file:") -> asyncPainterResource(Paths.get(URI.create(url)).toFile())
else -> asyncPainterResource(url)
}
I just exposed the URI(str: String) constructor in common. And it's loading the example...
but also looks like it works with just a string too 🤔:
It might just be an issue with your path
Ha! :)
The path is right as I can load the image if I pass a java.io.File
built from it.
I tried many variations but it doesn't work on Linux without my workaround! :thinking:
Ha! :)
The path is right as I can load the image if I pass a
java.io.File
built from it. I tried many variations but it doesn't work on Linux without my workaround! 🤔
So it appears, file://
is scoped to the jar's resources. That's why it is working for me.. But when I use an absolute path it does not
Right, the image path I use is for a png file from the OS file system, outside the application resources.
Lol, I see now I was editing the ResourcesFetcher test... so obviously loading resources was working 😅
Anyways: https://github.com/Kamel-Media/Kamel/pull/90
you can try it with: 0.10.0-SNAPSHOT
It should be working for local files with or without the "file://" prefix
@eskatos lmk if you get a chance to try it out
I just tried and it fails by default parsing a file:/path/to/image.png
URL which is what I get from other APIs.
If I manually change the URL to file:///path/to/image.png
then it works out of the box.
It looks like KTor URL parser is not correct as this syntax is described in Section 2 of the RFC as shown in examples in the Appendix B of the RFC.
I would understand you push this upstream to KTor at this point.
I just tried and it fails by default parsing a
file:/path/to/image.png
URL which is what I get from other APIs. If I manually change the URL tofile:///path/to/image.png
then it works out of the box. It looks like KTor URL parser is not correct as this syntax is described in Section 2 of the RFC as shown in examples in the Appendix B of the RFC.I would understand you push this upstream to KTor at this point.
If that's common I can add a case here:
kamel-core/src/commonMain/kotlin/io/kamel/core/mapper/Mappers.kt
But you might want to submit that issue to ktor anyway and tag it here
Here's the KTOR issue https://youtrack.jetbrains.com/issue/KTOR-6709
@eskatos I re-published with support for file:/
and file:///
in kamel-core/src/commonMain/kotlin/io/kamel/core/mapper/Mappers.kt
I got rid of assuming a /
prefix is a file because that would break things when using a defaultRequest with a base url.
Sorry it took me so long to get back to you. All good with you latest publication, thank you very much :heart: Any chance this could get into a released version?
@eskatos it should be in the 1.0 beta. The only reason it's beta is because it uses ktor 3.0
beta still. I'm waiting on a release.
Doing
asyncPainterResource("file://path/to/image.png")
currently fails with the following exception:I would have expected this to load the local image from the filesystem.
I do this from a
commonMain
source set where I can't usejava.io.File
.For the time being I worked around it with an
expect
/actual
function to callasyncPainterResource(File)
forfile:
URLs on the JVM platform. This is a totally viable workaround but supportingfile:
URLs out of the box would make Kamel easier to use.