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

How do I increase maximum amount of files per request? #57

Open
unclechu opened this issue Oct 3, 2021 · 2 comments
Open

How do I increase maximum amount of files per request? #57

unclechu opened this issue Oct 3, 2021 · 2 comments

Comments

@unclechu
Copy link

unclechu commented Oct 3, 2021

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: yesodweb/wai#855

@unclechu
Copy link
Author

unclechu commented Oct 5, 2021

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?

@vherrmann
Copy link

You can also just use

multipartCfg =
        MultipartOptions @Tmp
          (defaultParseRequestBodyOptions & W.clearMaxRequestNumFiles)
          (defaultBackendOptions (Proxy Tmp))
servantContext = multipartCfg :. S.EmptyContext

together with serveWithContext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants