Upload files (images) to games

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gcardozo

I was wondering if it’s possible to create an in-game FileDialog so players could upload an image from their own PC to be used as a Sprite.
The first problem I noticed is that the FileDialog seems to be stuck under res:// directory, I can’t access specific directories that weren’t packed with the game.

Is there a way to allow players to upload their own image files to a game?
I mean, the server (Itch.io for example) would not store that image, the game would just read it and create a Texture that then would be attached to a Sprite. I don’t know what type of HTTP request shenanigans this would involve.

:bust_in_silhouette: Reply From: AndyCampbell

Regarding the problem with the FileDialog being stuck under res:// did you set the “access” property?

By default, this is set to limit access to only res:// . So, in your case you need this to be either User data (ACCESS_USERDATA = 1) or Filesystem (ACCESS_FILESYSTEM = 2), right?

Using this I was able to popup a FileDialog and browse my local filesystem

There is an example of usage here

That solves the FileDialog part for desktop builds, but for HTML5 the file dialog then stays under a / directory containg the following paths:

- dev
- home
- proc
- tmp
- userfs
- <project_name>.pck

I didn’t find those paths on my system and I’m testing the HTML5 build on itch.io so I suppose that may be itch.io file system?

gcardozo | 2020-11-14 12:50

Yes, that is part of a standard unix filesystem (minus bin, sbin, etc, usr and lib).

This is how itch.io describe how html5 works on their platform : “itch.io supports HTML5 games by embedding an iframe pointing to your game on itch.io’s own game page.”, so that must be the filesystem of where your game is hosted in itch.io.

I guess they won’t let you write to that, but you might be able to save things in the home folder (or a subfolder)

AndyCampbell | 2020-11-14 17:19