Skip to content

Instantly share code, notes, and snippets.

@pveber
Created November 25, 2013 07:36
Show Gist options
  • Save pveber/7637719 to your computer and use it in GitHub Desktop.
Save pveber/7637719 to your computer and use it in GitHub Desktop.
site raising Input_is_too_large exception
{shared{
open Printf
open Eliom_content
open Eliom_content.Html5.F
open Eliom_parameter
}}
(*
(* uncomment this to fix the issue *)
let () = Ocsigen_config.set_maxrequestbodysizeinmemory 100000
*)
{client{
let file_of_input_element elt =
Js.Optdef.case
((Eliom_content.Html5.To_dom.of_input elt)##files)
(fun () -> Lwt.fail (Failure "file_of_input_element: 'files' attribute is undefined"))
(fun files ->
Js.Opt.case
(files##item(0))
(fun () -> Lwt.fail (Failure "file_of_input_element: no selected file"))
(fun x -> Lwt.return x))
}}
module App =
Eliom_registration.App (struct
let application_name = "input_too_large"
end)
let main_service = Eliom_service.service ~path:[ "" ] ~get_params:unit ()
let report_service =
Eliom_service.post_service
~fallback:main_service
~post_params:(string "pb")
()
let report_service_page () pb =
Lwt.return (
html
(head
(title (pcdata ""))
[])
(body [ pcdata pb ])
)
let main_service_body () =
let module H = Eliom_content.Html5.D in
let file_input = H.input ~input_type:`File ~a:[a_id "data-file-input"] () in
let module Html5 = Eliom_content.Html5.F in
let run_handler = {{
let open Lwt in
(fun _ ->
Lwt.async (fun () ->
lwt rq =
file_of_input_element %file_input >>= (fun file ->
File.readAsText file >|= Js.to_string
)
in
Lwt.return (Eliom_client.exit_to ~service:%report_service () rq)
)
)
}}
in
let run_button =
Eliom_content.Html5.D.button
~button_type:`Button
~a:[a_id "run-button" ; a_onclick run_handler]
[pcdata "Run"]
in
[
raw_form (div []) [ file_input ; run_button ]
]
let main_service_page () () =
Lwt.return
(html
(head
(title (pcdata "Input too large"))
[])
(body (main_service_body ())))
let () =
App.register
~service:report_service
report_service_page
let () =
App.register
~service:main_service
main_service_page
@bguil
Copy link

bguil commented Jun 22, 2020

Thanks for sharing. I hit the same problem and found the solution here!

@pveber
Copy link
Author

pveber commented Jun 22, 2020

You welcome, hopefully github has a better memory than me, I just didn't remember this code ;o).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment