/CometImport

A Comet-based file uploader written in Scala/Lift

Primary LanguageScala

A Comet-based pattern for importing files, written in Lift.

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.

The demo app.

... 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:

  1. extracts the file;
  2. starts a CometActor to display progress;
  3. spawns a thread (via the ChooseFile snippet) that processes the file line-by-line, sending progress reports to the CometActor.

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.

Generic pattern for creating an importer.

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 an ImportListener;

This pattern can be applied by subclassing Importer with the desired behaviour, and providing a (custom) instance of ImportListener.

More details on how the pattern is used in the demo

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:

  1. MessageQueueImportListener, which accumulates messages into a list;
  2. LiftActorImportListener, which sends messages on to CometUpload, our progress-reporting Comet-backed page.