view src/ur/ajaxUpload.urs @ 1:f84d5e8aa992

Complete working example with required submit button click
author Adam Chlipala <adam@chlipala.net>
date Thu, 29 Dec 2011 15:26:46 -0500
parents 0c0f903d9440
children df095eecba63
line wrap: on
line source
(** A simple widget for uploading files to the server without reloading the current page *)

type handle
(* Unique ID for a file that has been uploaded *)

datatype claim_result =
         NotFound (* That file was either claimed by someone else or was uploaded too long ago and never claimed. *)
       | Found of { Filename : option string,
                    MimeType : string,
                    Content : blob }

val claim : handle -> transaction claim_result
(* In server-side code, claim ownership of a [handle]'s contents, deleting the persistent record of the file data. *)

val render : {OnBegin : transaction {},
              (* Run this when an upload begins. *)
              OnSuccess : handle -> transaction {}
              (* Run this after a successful upload. *)}
             -> transaction xbody
(* Produce HTML for a file upload control *)