Back

Functions: static files not found in Kotlin

  • 0
  • Functions
shamanth
11 Oct, 2023, 16:41

My function structure looks like this:

TypeScript
kotlin
 - src
   - Main.kt
 - static
   - index.html

Entry point for the function is src/Main.kt

I'm getting java.lang.reflect.InvocationTargetException and Caused by: java.io.FileNotFoundException: ../static/index.html (No such file or directory) errors.

The code I'm using to read files is:

TypeScript
val text = File("../static/index.html").readText()

I've also tried

TypeScript
val fileName = Paths.get("..", "static", "index.html")
val fileString = Files.readString(fileName)

and many others without any luck.

TL;DR
The issue is that static files are not found in Kotlin functions because they are not bundled into the jar file when the Kotlin code is compiled. A potential solution is to update open runtimes to support static files. The provided code snippets to read the file have not worked so far.
Drake
14 Oct, 2023, 16:40

For anyone else finding this, the problem is the kotlin code is compiled into a jar and static files included in your function aren't bundled into the jar. We may need to update open runtimes to add support for static files.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more