[Haskell-cafe] Happstack: moving the uploaded file

Jeremy Shaw jeremy at n-heptane.com
Mon Jun 2 21:55:14 UTC 2014


You code does not work correctly because what you are trying to do
really requires three separate requests. You want the client to be
able to:

 1. do a GET request to receive the form
 2. do a POST request to upload the file
 3. do another GET request to view the file after it has been uploaded

In UploadFile.hs you have the first two steps merged together in
uploadForm. In UploadFile-working -- you have steps 2 and 3 oddly
separated and merged at the same time.

I have created a modified version that probably does what you want.

- jeremy

On Mon, Jun 2, 2014 at 3:31 PM, Nikita Karetnikov <nikita at karetnikov.org> wrote:
> I’m trying to create a trivial Happstack application based on the
> example from the “File Uploads” section of the Happstack book [1].
> It should work as follows:
>
> 1. If there is no file called ‘foo’ on disk, show the upload form at any
>    page.
>
> 2. If the file exists, show its contents at ‘localhost:8000/file’ and
>    the upload form at any other page.
>
> The difficulty is that initially the uploaded file is placed to a
> temporary location, but since I want to read the file later, I have to
> move it somewhere.  ‘UploadFile-working.hs’ uses two handlers for that,
> which doesn’t look right.  I’d like the code to look like
> ‘UploadFile.hs’, but it doesn’t work properly.  Could anyone explain
> why?
>
> [1] http://happstack.com/docs/crashcourse/index.html
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: UploadFile-more-correct.hs
Type: text/x-haskell
Size: 1864 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140602/e26ebb29/attachment.hs>


More information about the Haskell-Cafe mailing list