Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-8415: Alternative way to setup MiltiPart #6285

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package net.corda.rest.server.impl.internal

import io.javalin.Javalin
import io.javalin.config.JavalinConfig
import io.javalin.config.MultipartConfig
import io.javalin.config.SizeUnit
import io.javalin.http.BadRequestResponse
import io.javalin.http.ContentType
import io.javalin.http.Context
Expand All @@ -11,10 +13,8 @@ import io.javalin.http.HttpResponseException
import io.javalin.http.NotFoundResponse
import io.javalin.http.staticfiles.Location
import io.javalin.http.util.JsonEscapeUtil
import io.javalin.http.util.MultipartUtil
import io.javalin.json.JavalinJackson
import io.javalin.plugin.bundled.RedirectToLowercasePathPlugin
import jakarta.servlet.MultipartConfigElement
import net.corda.rest.authorization.AuthorizationUtils.authorize
import net.corda.rest.server.config.RestServerSettingsProvider
import net.corda.rest.server.impl.apigen.processing.RouteInfo
Expand Down Expand Up @@ -123,18 +123,12 @@ internal class RestServerInternal(
addOpenApiRoutes()
addWsRoutes()
// In order for multipart content to be stored onto disk, we need to override some properties
// which are set by default by Javalin such that entire content is read into memory
@Suppress("DEPRECATION")
MultipartUtil.preUploadFunction = { req ->
req.setAttribute(
"org.eclipse.jetty.multipartConfig",
MultipartConfigElement(
multiPartDir.toString(),
configurationsProvider.maxContentLength().toLong(),
configurationsProvider.maxContentLength().toLong(),
1024
)
)
// which are set by default by Javalin such that the entire content is read into memory
MultipartConfig().apply {
cacheDirectory(multiPartDir.toString())
maxFileSize(configurationsProvider.maxContentLength().toLong(), SizeUnit.BYTES)
maxTotalRequestSize(configurationsProvider.maxContentLength().toLong(), SizeUnit.BYTES)
maxInMemoryFileSize(1024, SizeUnit.BYTES)
}
}
}
Expand Down