open Js_of_ocaml open Brr let send : mime_type:Jstr.t -> filename:Jstr.t -> Jstr.t -> unit = fun ~mime_type ~filename content -> let btoa = Jv.get Jv.global "btoa" in let base64data = Jv.apply btoa [| Jv.of_jstr content |] in let mime = (Jv.Id.(of_jv @@ to_jv mime_type)) and base64 = (Jv.Id.(of_jv @@ to_jv base64data)) in let data = (Js.string "data:")##concat_3 mime (Js.string ";base64,") base64 in (* Create the link to download the the element, and simulate a click on it *) let a = El.a ~at:At.[ href Jv.Id.(of_jv @@ to_jv data) ; v (Jstr.v "download") filename ] [] in El.click a