@@ -61,6 +61,10 @@ import qualified Data.ByteString.Lazy as LBS
61
61
-- stand now. This also means that 'MultipartForm' can't be used in
62
62
-- conjunction with 'ReqBody' in an endpoint.
63
63
--
64
+ -- The 'tag' type parameter instructs the function to handle data
65
+ -- either as data to be saved to temporary storage ('Tmp') or saved to
66
+ -- memory ('Mem').
67
+ --
64
68
-- The 'a' type parameter represents the Haskell type to which
65
69
-- you are going to decode the multipart data to, where the
66
70
-- multipart data consists in all the usual form inputs along
@@ -73,12 +77,12 @@ import qualified Data.ByteString.Lazy as LBS
73
77
-- Example:
74
78
--
75
79
-- @
76
- -- type API = MultipartForm MultipartData :> Post '[PlainText] String
80
+ -- type API = MultipartForm Tmp ( MultipartData Tmp) :> Post '[PlainText] String
77
81
--
78
82
-- api :: Proxy API
79
83
-- api = Proxy
80
84
--
81
- -- server :: MultipartData -> Handler String
85
+ -- server :: MultipartData Tmp -> Handler String
82
86
-- server multipartData = return str
83
87
--
84
88
-- where str = "The form was submitted with "
@@ -100,12 +104,12 @@ import qualified Data.ByteString.Lazy as LBS
100
104
-- @
101
105
-- data User = User { username :: Text, pic :: FilePath }
102
106
--
103
- -- instance FromMultipart User where
107
+ -- instance FromMultipart Tmp User where
104
108
-- fromMultipart multipartData =
105
109
-- User \<$\> lookupInput "username" multipartData
106
110
-- \<*\> fmap fileContent (lookupFile "pic" multipartData)
107
111
--
108
- -- type API = MultipartForm User :> Post '[PlainText] String
112
+ -- type API = MultipartForm Tmp User :> Post '[PlainText] String
109
113
--
110
114
-- server :: User -> Handler String
111
115
-- server usr = return str
@@ -132,6 +136,10 @@ data MultipartForm tag a
132
136
133
137
-- | What servant gets out of a @multipart/form-data@ form submission.
134
138
--
139
+ -- The type parameter 'tag' tells if 'MultipartData' is stored as a
140
+ -- temporary file or stored in memory. 'tag' is type of either 'Mem'
141
+ -- or 'Tmp'.
142
+ --
135
143
-- The 'inputs' field contains a list of textual 'Input's, where
136
144
-- each input for which a value is provided gets to be in this list,
137
145
-- represented by the input name and the input value. See haddocks for
@@ -147,17 +155,13 @@ data MultipartData tag = MultipartData
147
155
, files :: [FileData tag ]
148
156
}
149
157
150
-
151
-
152
- -- TODO: this is specific to Tmp. we need a version that
153
- -- can handle Mem as well.
154
- fromRaw :: forall options . ([Network.Wai.Parse. Param ], [File (MultipartResult options )]) -> MultipartData options
158
+ fromRaw :: forall tag . ([Network.Wai.Parse. Param ], [File (MultipartResult tag )]) -> MultipartData tag
155
159
fromRaw (inputs, files) = MultipartData is fs
156
160
157
161
where is = map (\ (name, val) -> Input (dec name) (dec val)) inputs
158
162
fs = map toFile files
159
163
160
- toFile :: File (MultipartResult options ) -> FileData options
164
+ toFile :: File (MultipartResult tag ) -> FileData tag
161
165
toFile (iname, fileinfo) =
162
166
FileData (dec iname)
163
167
(dec $ fileName fileinfo)
@@ -305,7 +309,7 @@ fuzzyMultipartCTCheck ct
305
309
--
306
310
-- 'generalOptions' lets you specify mostly multipart parsing
307
311
-- related options, such as the maximum file size, while
308
- -- 'tmpOptions ' lets you configure aspects specific to
312
+ -- 'options ' lets you configure aspects specific to
309
313
-- the temporary file backend. See haddocks for
310
314
-- 'ParseRequestBodyOptions' and 'TmpBackendOptions' respectively
311
315
-- for more information on what you can tweak.
@@ -328,10 +332,10 @@ class MultipartBackend tag where
328
332
329
333
defaultBackendOptions :: Proxy tag -> MultipartBackendOptions tag
330
334
331
- -- | Tag for temporary files
335
+ -- | Tag for data stored as a temporary file
332
336
data Tmp
333
337
334
- -- | Tag for items in memory
338
+ -- | Tag for data stored in memory
335
339
data Mem
336
340
337
341
instance MultipartBackend Tmp where
@@ -373,7 +377,7 @@ defaultTmpBackendOptions = TmpBackendOptions
373
377
-- | Default configuration for multipart handling.
374
378
--
375
379
-- Uses 'defaultParseRequestBodyOptions' and
376
- -- 'defaultTmpBackendOptions ' respectively.
380
+ -- 'defaultBackendOptions ' respectively.
377
381
defaultMultipartOptions :: MultipartBackend tag => Proxy tag -> MultipartOptions tag
378
382
defaultMultipartOptions pTag = MultipartOptions
379
383
{ generalOptions = defaultParseRequestBodyOptions
0 commit comments