简体   繁体   English

在Snap Framework中的文件上传处理程序(handleMultiPart)中显示进度状态

[英]Showing progress status in file upload handler (handleMultiPart) in Snap Framework

I am using Snap framework to prototype a web application. 我正在使用Snap框架来原型化Web应用程序。 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. 我正在尝试使用Snap.Util.FileUploads.handleMultiPart上载文件,立即使用iteratee处理该文件,同时在同一页面上显示进度消息。

It is possible to hook Data.Enumerator.printChunks to debug progress on the console. 可以挂接Data.Enumerator.printChunks来调试控制台上的进度。 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? 文件上传期间如何使用handleMultiPart显示进度消息?

Also handleMultiPart takes PartInfo -> Iteratee ByteString IO a to handle the file upload. handleMultiPart需要PartInfo -> Iteratee ByteString IO a来处理文件上传。 Should handleMultiPart rather take MonadIO m => PartInfo -> Iteratee ByteString ma to make it simpler? handleMultiPart应该使用MonadIO m => PartInfo -> Iteratee ByteString ma使其更简单吗?

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. 通常,我不知道在上传文件时是否可以通过推送HTML响应在客户端显示进度。 To the best of my knowledge, web apps that do this are typically using some JavaScript API or Flash widget to do so. 据我所知,执行此操作的Web应用程序通常使用某些JavaScript API或Flash小部件来执行此操作。 Certainly it's not possible using handleMultiPart . 当然,使用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. 但是,流传输到控制台是另一回事–您可以轻松地提供一个枚举者,该枚举者记录大块信息(或者更新MVar,以替代方式),然后将控制权传递给下游。 This will be less brain-bending in snap 1.0 (nearing release), which will use io-streams which are much easier to think about. 在snap 1.0(近乎发行)中,这将减少大脑的弯曲,它将使用更容易考虑的io流。

Finally, handleMultiPart works over IO because to do otherwise would require the "run" action for the monad, ie the inverse lift from (ma -> IO a). 最后,handleMultiPart在IO上工作,因为否则将需要对monad进行“运行”操作,即从(ma-> 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. 有很多方法可以做这种事情,但是snap <1.0并不能解决问题,对不起---在snap 1.0中,这个问题将不复存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM