当前位置: 动力学知识库 > 问答 > 编程问答 >

haskell - Showing progress status in file upload handler (handleMultiPart) in Snap Framework

问题描述:

I am using Snap framework to prototype a web application. I am trying to use Snap.Util.FileUploads.handleMultiPart to upload a file, immediately process it using iteratee, and at the same time display the progress message on the same page.

It is possible to hook Data.Enumerator.printChunks to debug progress on the console. I could not figure out how to display the progress on the same page while processing the file upload. How can a progress message be displayed using handleMultiPart during file upload?

Also handleMultiPart takes PartInfo -> Iteratee ByteString IO a to handle the file upload. Should handleMultiPart rather take MonadIO m => PartInfo -> Iteratee ByteString m a to make it simpler?

网友答案:

In general I don't know if it's possible to display progress on the client side via pushing an HTML response while the file is being uploaded. To the best of my knowledge, web apps that do this are typically using some JavaScript API or Flash widget to do so. Certainly it's not possible using handleMultiPart.

Streaming to the console is another matter, however -- you can easily provide an enumeratee that logs chunk information (or updates an MVar, for an alternative) and then passes control downstream. This will be less brain-bending in snap 1.0 (nearing release), which will use io-streams which are much easier to think about.

Finally, handleMultiPart works over IO because to do otherwise would require the "run" action for the monad, i.e the inverse lift from (m a -> IO a). There are ways to do this kind of thing but snap <1.0 doesn't do them, sorry --- and in snap 1.0 the issue will be moot.

分享给朋友:
您可能感兴趣的文章:
随机阅读: