Important: This news article covers an old version of Javalin (v0.3.6). The current version is v6.3.0.
See the documentation page for up-to-date information.

Uploads, uploads everywhere!

Uploaded files are now easily accessible via: ctx.uploadedFiles()

  • Java
  • Kotlin
app.post("/upload", ctx -> {
    ctx.uploadedFiles("files").forEach(file -> {
        FileUtils.copyInputStreamToFile(file.getContent(), new File("upload/" + file.getName()));
    });
});
app.post("/upload") { ctx ->
    ctx.uploadedFiles("files").forEach { (contentType, content, name, extension) ->
        FileUtils.copyInputStreamToFile(content, File("upload/" + name))
    }
}

Other changes:

  • ctx.formParam() now uses same decoding as ctx.queryParam()
  • .start() is now required in order to start the server (previously declaring routes would also start the server)