From 1351eb495dca472ac1116dc25eacdc4d38a49fe9 Mon Sep 17 00:00:00 2001 From: t3du <32546729+t3du@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:02:22 -0300 Subject: [PATCH] Add files via upload --- armory/Sources/armory/logicnode/WriteFileNode.hx | 9 +++++++++ armory/Sources/armory/logicnode/WriteJsonNode.hx | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/armory/Sources/armory/logicnode/WriteFileNode.hx b/armory/Sources/armory/logicnode/WriteFileNode.hx index 2fe87a16b3..4e3e8850c5 100644 --- a/armory/Sources/armory/logicnode/WriteFileNode.hx +++ b/armory/Sources/armory/logicnode/WriteFileNode.hx @@ -15,6 +15,15 @@ class WriteFileNode extends LogicNode { var path = Krom.getFilesLocation() + "/" + file; var bytes = haxe.io.Bytes.ofString(data); Krom.fileSaveBytes(path, bytes.getData()); + + #elseif kha_html5 + var blob = new js.html.Blob([data], {type: "application"}); + var url = js.html.URL.createObjectURL(blob); + var a = cast(js.Browser.document.createElement("a"), js.html.AnchorElement); + a.href = url; + a.download = file; + a.click(); + js.html.URL.revokeObjectURL(url); #end } } diff --git a/armory/Sources/armory/logicnode/WriteJsonNode.hx b/armory/Sources/armory/logicnode/WriteJsonNode.hx index 8bd70c6602..cb71600757 100644 --- a/armory/Sources/armory/logicnode/WriteJsonNode.hx +++ b/armory/Sources/armory/logicnode/WriteJsonNode.hx @@ -11,12 +11,20 @@ class WriteJsonNode extends LogicNode { var file: String = inputs[1].get(); var data: Dynamic = inputs[2].get(); var s = haxe.Json.stringify(data); - trace(s); #if kha_krom var path = Krom.getFilesLocation() + "/" + file; var bytes = haxe.io.Bytes.ofString(s); Krom.fileSaveBytes(path, bytes.getData()); + + #elseif kha_html5 + var blob = new js.html.Blob([s], {type: "application/json"}); + var url = js.html.URL.createObjectURL(blob); + var a = cast(js.Browser.document.createElement("a"), js.html.AnchorElement); + a.href = url; + a.download = file; + a.click(); + js.html.URL.revokeObjectURL(url); #end } }