- Home /
A good way to save an image in Unity webplayer and send it to a server?
I am a junior programmer and my team and I are making a game in Unity for the web. We are using Unity webplayer to run it.
***The problem: For our game, we want to save an image/texture that a player made in our Unity game, send it to our server, then another player can retrieve it. We're not really sure how to save this image and send it to our server as an image file format. Our server is Heroku (using Ruby on Rails 3.1) and the server then sends it to Amazon S3 (storage site.)
We have an issue sending the image from a Unity wwwform to our server. Unity sends an image via a byte array, however S3 does not hold images as a byte array. It only holds images in regular file formats. We found some java code that can convert a byte array to a png, but our server is using Ruby on Rails 3.1.
***What we're thinking: One thing we thought to do is this: Is it possible to embed java code as a .jar file in the server and run it as an executable and send it off to S3?
As far as saving images locally to a user's computer, does this raise some kind of security issue or is there a way to bypass that?
We were thinking of using PlayerPrefs but that doesn't save images...
Any other input and ideas to solve our problem would help! Thank you!
Answer by DaveA · Mar 25, 2012 at 10:23 PM
There is code here: http://unity3d.com/support/documentation/ScriptReference/Texture2D.EncodeToPNG.html If that's not working my guess is you may need to set some headers 'manually' using UniWeb
Answer by by0log1c · Mar 25, 2012 at 11:08 PM
Is there a reason why you choose to use Amazon storage service rather than your own webserver? I've done it before and the way I used is this, it might not be the only/best way but it works:
Setup a webserver allowing PHP. You may get a free one from many online providers.
Create a PHP upload script, W3S example here.
In Unity, follow the EncodeToPNG example to upload to the PHP upload script.
Fetch the image by creating a WWW pointing to the uploaded image with WWW.LoadImageIntoTexture.