servant-multipart
servant-multipart copied to clipboard
How do I increase maximum amount of files per request?
After implementing a tiny service I realized that there is a limit of maximum amount of files which is just 10 files.
I found this option https://hackage.haskell.org/package/wai-extra-3.1.6/docs/Network-Wai-Parse.html#v:setMaxRequestNumFiles and was trying to figure out how to apply it using servant-multipart. I found here https://hackage.haskell.org/package/servant-multipart-0.12.1/docs/src/Servant.Multipart.html that it uses defaultMultipartOptions which has defaultParseRequestBodyOptions which I probably want to modify here.
I was trying to implement overlapping HasServer (MultipartForm' mods tag a :> sublayout) config instance but it turns out it uses some functions that are not exported from Servant.Multipart. It’s getting trickier. Is there any way to override ParseRequestBodyOptions for that instance?
See also: https://github.com/yesodweb/wai/issues/855
This ad-hoc patch (for v0.12 tag) works for me:
diff --git a/servant-multipart.cabal b/servant-multipart.cabal
index cf6cf83..10bed0b 100644
--- a/servant-multipart.cabal
+++ b/servant-multipart.cabal
@@ -46,7 +46,7 @@ library
, servant-server >=0.16 && <0.19
, string-conversions >=0.4.0.1 && <0.5
, wai >=3.2.1.2 && <3.3
- , wai-extra >=3.0.24.3 && <3.1
+ , wai-extra >=3.0.24.3 && <3.2
executable upload
hs-source-dirs: exe
diff --git a/src/Servant/Multipart.hs b/src/Servant/Multipart.hs
index 9164e1b..d4a225f 100644
--- a/src/Servant/Multipart.hs
+++ b/src/Servant/Multipart.hs
@@ -583,7 +583,7 @@ defaultTmpBackendOptions = TmpBackendOptions
-- 'defaultBackendOptions' respectively.
defaultMultipartOptions :: MultipartBackend tag => Proxy tag -> MultipartOptions tag
defaultMultipartOptions pTag = MultipartOptions
- { generalOptions = defaultParseRequestBodyOptions
+ { generalOptions = setMaxRequestNumFiles 999 defaultParseRequestBodyOptions
, backendOptions = defaultBackendOptions pTag
}
But the question is still open. How I could customize those options on the API level?