How to send a file (upload)?

To upload a file, use Eliom_parameter.file as service parameter type.

Ocsigen server will save the file at a temporary location and keep it there during the request. Then the file will be removed. You must link it somewhere else on the disk yourself if you want to keep it.

Be careful also to set the right option in Ocsigen server's configuration file. For example:

<ocsigen>
  <server>
    <uploaddir>/var/www/tmp</uploaddir>
    <maxuploadfilesize>2MB</maxuploadfilesize>
    <maxrequestbodysize>100MB</maxrequestbodysize>
  </server>
</ocsigen>

Example with Eliom_content.Html.D module opened:

let upload = Eliom_service.Http.create
    ~path:(Eliom_service.Path ["upload"])
    ~meth:(Eliom_service.Get Eliom_parameter.unit)
    ()

let upload2 =
  Eliom_registration.Html.create
    ~path:(Eliom_service.Path ["upload"])
    ~meth:(Eliom_service.Post
             (Eliom_parameter.unit,
              Eliom_parameter.file "file"))
    (fun () file ->
      let newname = "/var/www/upload/thefile" in
      (try
        Unix.unlink newname;
      with _ -> ());
      Lwt_unix.link (Eliom_request_info.get_tmp_filename