Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow downloading files from the virtual file systems of HTML games #27992

Closed
Astral-Cyrusa opened this issue Apr 13, 2019 · 6 comments
Closed

Comments

@Astral-Cyrusa
Copy link

Astral-Cyrusa commented Apr 13, 2019

Godot version: 3.1
OS/device including version: Windows 10
Issue description:
I would like to make an HTML application that allows the user to move images around to build a map and then download the map as a png image.
This issue is about the downloading part.

For a native application, I would have godot make the map image, and then use the save_png function of the Image class to save it to the user's disk.

But on HTML, Godot does not have access to the user's file system (for good security reasons), so save_png saves the image to some sort of virtual file system instead (see picture). From there, I would like to be able to have the browser open a download dialog for this file, but I have not found a way to do this in the Godot documentation.

image

So feature request: a way to tell the browser running an HTML game to open a download dialog for a file present in the virtual file system godot html games have access to.

Related issue: #18947
In this issue, someone suggests using JavaScript.eval(). I tried a few things but the issue is that Javascript does not have access to the game's virtual file system where the png is.

Minimal reproduction project:
HtmlDownloadPng.zip

@LinuxUserGD
Copy link
Contributor

Maybe this will be possible when Godot will be available on HTML5 as it was previously with godot.online

@mhilbrunner
Copy link
Member

Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine.

The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker.

If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance!

@Yesyoor
Copy link

Yesyoor commented Dec 1, 2021

Has this been archived? How can I keep track of the development going on?

@LinuxUserGD
Copy link
Contributor

Has this been archived? How can I keep track of the development going on?

By creating a new feature request at https://github.com/godotengine/godot-proposals

@Calinou
Copy link
Member

Calinou commented Dec 2, 2021

Downloading files from the virtual system in HTML5 is already implemented in Godot 3.4 with #48929 (JavaScript.download_buffer()). You can load a file from the virtual filesystem using the File class, get its contents as a PoolByteArray and pass them to JavaScript.download_buffer().

@berlinnights
Copy link

berlinnights commented May 20, 2022

1. Version: Accessing buffer directly from Image class

func Download_File(_img,_filename):
	var buf = _img.save_png_to_buffer()
	JavaScript.download_buffer(buf,_filename+".png")

2. Version: Accessing buffer from File class, as mentioned above by Calinou

func Save_PNG(_img,_path,_filename):
	var _err = _img.save_png(_path+"/"+_filename+".png")
	Download_File(_path+"/"+_filename+".png",_filename)
        #Put Error Handling Here

func Download_File(_path,_filename):
	var f = File.new()
	f.open(_path,File.READ)
	var buf = f.get_buffer(f.get_len())
	JavaScript.download_buffer(buf,_filename+".png")
	f.close()

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

No branches or pull requests

8 participants