Leon Smith <[email protected]> writes:
> I'm assuming that by "automagically" handing form data, you mean
> automatically parsing the data and having it appear in getParam?
>
> Any ideas of what the API should look like? I'm thinking that you
> should be able to set some kind of iterator that handles the form
> data...
>
> This would actually be useful for my current project, so I'll try
> taking a crack at it this week.
Well, it might be good to start with looking at what Yesod and Happstack
do as a starting point for higher-level features.
On an underlying level, a multipart form data message contains something
like a bunch of (Header, Body) pairs, so what to do with them is a
matter of policy. I'd suggest something like:
processMultipartFormData :: (MonadSnap m) =>
(SomeKindOfHeader -> Iteratee m ())
-> m ()
or
processMultipartFormData :: (MonadSnap m) =>
(SomeKindOfHeader -> Iteratee m a)
-> m [a]
i.e. you'd pass in a snap monad action that gets folded over the stream
of body parts. We'd probably have a couple of ready-made functions to
handle this, including a default one which puts form parameters in
the rqParams and either puts file uploads in a temporary directory or
streams over them:
defaultMultipartHandler :: (MonadSnap m) =>
Int64 -- ^ max file size
-> (FilePath -> m ()) -- ^ what do we do if
-- we get a file?
-> SomeKindOfHeader
-> Iteratee m ()
The "right thing to do" here isn't 100% clear, it might be a good idea
to spend some discussion time hashing out potential solutions.
Cheers,
G
--
Gregory Collins <[email protected]>
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap