The documentation at hackage.haskell.org/package/servant-multipart says about the main combinator type MultipartForm tag a following:
Note that the behavior of this combinator is configurable, by using
serveWithfrom servant-server instead ofserve, which takes an additionalContextargument. It simply is an heterogeneous list where you can for example store a value of typeMultipartOptionsthat has the configuration that you want, which would then get picked up by servant-multipart.
And later:
data MultipartOptions tag
Global options for configuring how the server should handle multipart data.
generalOptionslets you specify mostly multipart parsing related options, such as the maximum file size …
However, I don't understand how to correctly call the mentioned serveWithContext:
serveWithContext 
  :: (HasServer api context, ServerContext context) 
  => Proxy api 
  -> Context context 
  -> Server api  
  -> Application
Searching for its usage on GitHub also didn't enlighten me, unfortunately.
Following code does the job:
import Prelude (($))
import Servant
  ( Application, Proxy(Proxy)
  , Context(EmptyContext, (:.)), serveWithContext
  )
import Servant.Multipart
  ( MultipartOptions(generalOptions)
  , defaultMultipartOptions, Mem
  )
import Network.Wai.Parse
  ( defaultParseRequestBodyOptions, setMaxRequestFileSize )
app :: Application
app =
  let
    size10MB = 10000000
    multipartOpts = (defaultMultipartOptions (Proxy :: Proxy Mem))
      { generalOptions =
          setMaxRequestFileSize size10MB
          defaultParseRequestBodyOptions
      }
    context = multipartOpts :. EmptyContext
  in
    serveWithContext appApi context appSserver
Make sure to use the correct MultipartData tag for the Proxy type (Mem or Tmp). Documentation: hackage.haskell.org/package/servant-multipart
You can check out hackage.haskell.org/package/wai-extra for all available config changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With