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:


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 =
    ~path:(Eliom_service.Path ["upload"])
              Eliom_parameter.file "file"))
    (fun () file ->
      let newname = "/var/www/upload/thefile" in
        Unix.unlink newname;
      with _ -> ()); (Eliom_request_info.get_tmp_filename