jaspervdj/digestive-functors — pull request #25 by dbp (2012-03-29 22:27:22+00:00)
Title: FileInput / multipart support for digestive-functors-snap

Hi Jasper,

Here is code to add fileinput / multipart support to the snap backend. The one thing that might seem funny (at first glance) is that we create a new temporary file, and copy the old temporary file to this new one. This is an artifact of how snap handles uploads - there is no way to tell snap to write the files to a temporary location and not erase them whenever the handler function finishes (unless we wanted to reimplement the whole upload machinery). Since we need the temporary file to be available later (specifically, so we can pass it back to whoever called us), we create a new temporary file, by prefixing with an underscore (arbitrary, but should make them not collide), and appending the original filename, if it exists (this will, as a side effect, make it have the right extension).

I've been using this with a test application, and it seems to work, though I'm sure there are ways that it could be tuned.

The only part that I'm not crazy about is picking the tmp directory ourselves. We could allow one to be specified in runFormWith, but I honestly think that people will often want to change the upload policy (the default one has a max size of 128kb), but will probably be usually happy with the default tmp directory, and that it would therefore be nice to not have to specify the tmp directory. Another option would be to provide runFormWith' which also took the tmp directory, and runFormWith would just pick the system default and call runFormWith'.

A place to improve is with error conditions - we are given any errors that occur (if the file is too big, etc), but I wasn't sure how to propagate that properly - probably just that I'm not familiar with the code. We are given the errors in storeFile - the Left is an error (which you see I ignore).

Either way, this could be a starting point.

Cheers,
Daniel