- Home /
upload png receives multiple results from server
I am uploading a photograph to a server which analyzes it. The code I'm using is from the unity documentation. It works fine but the response back from the server happens multiple times. The function to upload the png fires once but I get two-three results from the server in w.text. There is a delay of about 10-15 seconds between the server messages as if the original is being sent more than once.
The process of uploading a png and getting a message from the server is about 20 seconds which is normal for the service. Is that causing it to send the original repeatedly? I tried to use w.Dispose(), but it doesn't seem to stop the problem.
Dan
function uploadPng () {
Debug.Log("uploading a png");
// We should only read the screen buffer after rendering is complete
yield WaitForEndOfFrame();
tex.ReadPixels (Rect(left, screenheight-top-picheight, picwidth, picheight), 0, 0);
tex.Apply ();
// Encode texture into PNG
var bytes = tex.EncodeToPNG();
Destroy (tex);
// For testing purposes, also write to a file in the project folder
File.WriteAllBytes(Application.streamingAssetsPath + "/temp.png", bytes);
var form = new WWWForm();
var headers=form.headers;
form.AddBinaryData("pict",bytes,"pict","image/png");
var w = WWW("http://someurl", form);
yield w;
if (w.error != null) {
Debug.Log(w.error);
} else {
Debug.Log(w.text);
}
}
The results of running this are "Uploading a png"; "png has been successfully uploaded" "png has been successfully uploaded"