- Home /
uploading png with wwwform
I'm trying to upload a png to a service but I'm getting the following www error:
necessary data rewind wasn't possible.
I'm working on a mac standalone with unity 4.6.
I looked up the similar errors people posted about redirects, or problems with php on the their own servers, but this is a known service that accepts thousands of photo uploads a day so it is not those problems. The instructions they gave were the following:
<form action="http://www.someservice.com/upload"
method="post"
enctype="multipart/form-data">
<input type="text" name="username" value="">
<input type="password" name="password" value="">
<input type="yourfile" name="file">
</form>
This is what I'm trying to duplicate in Unity.
The code I'm using to grab and save the picture is below. Grabbing and saving the picture work fine. I can open it in my streaming assets folder after the code runs:
var tex = new Texture2D (picwidth, picheight, TextureFormat.RGB24, false);
// Read screen contents into the texture Rect(0,0 is lower left and then goes up the width and height I think.
tex.ReadPixels (Rect(left, screenheight-top-picheight, picwidth, picheight), 0, 0);
tex.Apply ();
// Encode texture into PNG
var bytes = tex.EncodeToPNG();
File.WriteAllBytes(Application.streamingAssetsPath + "/pic.png", bytes);
var form = new WWWForm();
form.AddBinaryData("file",bytes,"pic.png","image/png");
form.AddField("username","myusername");
form.AddField("password","mypassword");
// Upload to a cgi script
var w = WWW("http://www.someservice.com/upload", form);
yield w;
if (w.error != null) {
print(w.error);
} else {
Debug.Log(w.text);
print("Finished Uploading Screenshot");
}
Have you tried using telnet/wget/curl/a similar utility to confirm that the response does not contain a redirect header or anything of the sort?