open Brr (** Send a file to the user. *) 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 data = Jv.to_jstr @@ Jv.call (Jv.of_string "data:") "concat" [| Jv.of_jstr mime_type ; Jv.of_jstr (Jstr.v ";base64,") ; base64data |] 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