This project is a proof-of-concept for a file uploading paradigm using Comet. Essentially, you upload a file to the site, and it reports import progress via Comet.
... runs on port 8765 by default. Change by overriding project/build/Project.scala jettyPort
The index.html page is a form for choosing and uploading a file. When a file is chosen, it is submitted as form-data to the comet-import.html page, which:
- extracts the file;
- starts a
CometActor
to display progress; - spawns a thread (via the
ChooseFile
snippet) that processes the file line-by-line, sending progress reports to theCometActor
.
The import process also has a preview mode, which is turned on here. Essentially, the file is uploaded in preview mode to begin with, and progress is reported. Once the upload is complete, the user is presented with the option to import the file again, but this time "for real". Either import processed can be cancelled at any time.
The above is an instantiation of an importer pattern, comprising:
ImportListener
, a trait that provides some basic progress reporting tools;Importer
, a trait that provides synchronous and asynchronous importing facilities, reporting to anImportListener
;
This pattern can be applied by subclassing Importer
with the desired behaviour, and providing a (custom) instance of ImportListener
.
The specific incarnation deployed in this example Lift webapp uses a DummyImporter
, which simply pulls the file apart line-by-line and sends each line to a ImportListener
as a message (with a short delay).
Two ImportListener
subtypes are provided:
MessageQueueImportListener
, which accumulates messages into a list;LiftActorImportListener
, which sends messages on toCometUpload
, our progress-reporting Comet-backed page.