Hello, Is there an easy way to load an image as a...
# javascript
u
Hello, Is there an easy way to load an image as a byte array from the resources folder? (FYI I'm using Kobweb)
t
Webpack
file-loader
?
u
Is that a package available for Kotlin?
j
If running in a browser, you can just do an http get on your image and load it that way. Stuff in the resources folder is copied over to your server root. Ktor client could work for that. Or you just use the built in browser APIs.
t
file-loader
can add hash for static resources to avoid cache problems
j
only at build time ...
c
You should ask in #kobweb, I believe the framework has helpers for accessing resources, but I couldn't tell you how from the top of my head
d
Thanks @CLOVIS! Yeah I haven't traditionally watched this channel, so in the future, #kobweb is the way to go. (I catch questions in #compose-web as well). @アウスジョン(アウス) I actually saw you ask this question on our Discord server, which is a great place to get answers, so I think you already learned what you needed. But for anyone else curious, Kobweb is a Kotlin/JS web framework built on top of Compose HTML, and it has a few utility methods that help with loading a file from / saving a file to disk that anyone here is welcome to fork (FileUtils.kt). More than that, however, we discussed how there isn't really a traditional "resource bundle" for websites like there are for JVM applications. We discussed how a server somewhere usually hosts resources, and then you fetch them via a GET request. Kobweb provides a convenience class for doing this called HttpFetcher (accessed via a
window.http
extension property) but you can of course use
window.fetch
directly.