https://kotlinlang.org logo
#javascript
Title
# javascript
u

アウスジョン(アウス)

11/08/2023, 3:04 PM
Hello, Is there an easy way to load an image as a byte array from the resources folder? (FYI I'm using Kobweb)
t

turansky

11/09/2023, 12:29 AM
Webpack
file-loader
?
u

アウスジョン(アウス)

11/09/2023, 2:59 AM
Is that a package available for Kotlin?
j

Jilles van Gurp

11/09/2023, 7:54 AM
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

turansky

11/09/2023, 10:20 AM
file-loader
can add hash for static resources to avoid cache problems
j

Jilles van Gurp

11/09/2023, 10:28 AM
only at build time ...
c

CLOVIS

11/09/2023, 4:42 PM
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

David Herman

11/09/2023, 5:06 PM
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.
4 Views