[Solved] How do I store a user uploaded image locally

Get help using Construct 2

Post » Mon Oct 19, 2015 12:00 am

I'm working on a game concept that allows for the user to create a character, and part of this involves the user browsing their device for an image that will be used for the character. I have been able to select an image using the filechooser and then use the URI to lead a sprite just fine.The issue arises when I try and find a way for the image they selected to be saved for later game sessions. The URI code that the filechooser provides seems to expire when you restart the game, and using a savestate does not seem to preserve the image either.

Am I just doing this wrong, or otherwise is there a different way to accomplish this?

Edit: I settled on storing base64 encodings of the images in an array in the local storage, and then injecting those encodings into my sprites later. I consider this solved.
Last edited by draganviper on Tue Oct 20, 2015 11:46 pm, edited 3 times in total.
B
6
S
1
Posts: 20
Reputation: 817

Post » Mon Oct 19, 2015 1:28 am

if you target desktop, you can do this with NW.JS object
Image Image
B
22
S
13
G
135
Posts: 871
Reputation: 70,320

Post » Mon Oct 19, 2015 2:03 am

I'm aiming for android, but it is good to know that there's an option at least for the desktop.
B
6
S
1
Posts: 20
Reputation: 817

Post » Tue Oct 20, 2015 1:29 am

It seems like you should be able to somehow just save a directory in C:\ style format the way it displays in the filechooser during runtime after you've chosen a file and then use that for later reference, but the appropriate methods to do something like that don't appear to exist. Maybe there's a plugin for that kind of thing?
B
6
S
1
Posts: 20
Reputation: 817

Post » Tue Oct 20, 2015 4:05 am

Today I've been trying to make this work by storing the base64 version of an image into localstorage and then pulling it out to inject back into the image later, but now the problem with that seems to be that the storage doesn't allow enough space for a base64 encoding of an image...
B
6
S
1
Posts: 20
Reputation: 817

Post » Tue Oct 20, 2015 11:44 pm

Further experimenting has convinced me that storing the base64 encodings of then user's selected custom images is the way to go. It turns out the reason I was running into trouble was that I had WebGL enabled, and that seems to interfere with the base64 injection addon I was using. Turning off webgl made things run smoothly, and it seems that local storage does allow for strings long enough to store the encoded images. Even if they wouldn't fit, I could always chop the encoding strings into segments and store those to reassemble later.

All in all, I'm satisfied with this solution.
B
6
S
1
Posts: 20
Reputation: 817


Return to How do I....?

Who is online

Users browsing this forum: fearfulelephants and 20 guests