mirror of
https://github.com/godotengine/godot.git
synced 2025-11-02 14:41:07 +00:00
[HTML5] Add easy to use download API.
New `JavaScript.download_buffer` method to create a prompt that let the user download a file.
This commit is contained in:
parent
c311b4c039
commit
bf078814cc
8 changed files with 51 additions and 61 deletions
|
|
@ -304,6 +304,23 @@ const GodotOS = {
|
|||
godot_js_os_hw_concurrency_get: function () {
|
||||
return navigator.hardwareConcurrency || 1;
|
||||
},
|
||||
|
||||
godot_js_os_download_buffer__sig: 'viiii',
|
||||
godot_js_os_download_buffer: function (p_ptr, p_size, p_name, p_mime) {
|
||||
const buf = GodotRuntime.heapSlice(HEAP8, p_ptr, p_size);
|
||||
const name = GodotRuntime.parseString(p_name);
|
||||
const mime = GodotRuntime.parseString(p_mime);
|
||||
const blob = new Blob([buf], { type: mime });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = name;
|
||||
a.style.display = 'none';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
},
|
||||
};
|
||||
|
||||
autoAddDeps(GodotOS, '$GodotOS');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue