Hello there.
I'm trying to upload a new target using the Unity WWW class.
My only problem is that I don't know how to calculate the MD5 hash to include in the request.
What I'm doing is create the JSON of the Texture2D with this function:
private byte[] CreateImageJSON (Texture2D image, string name, int width = 1) { string json = "{\"name\":\"" + name + "\", \"width\":" + width + ", \"image\":\""; json += Convert.ToBase64String (image.EncodeToJPG ()); json += "\"}"; if (s_verboseEnabled) { Debug.LogWarning ("image json: " + json); } return Encoding.UTF8.GetBytes (json); }
I will then assign the data to a WWForm:
form.AddBinaryData ("Request", CreateImageJSON (image, image.name));
and finally calculate the MD5 with this other function passing the form.data as parameter:
private string GetMD5Hash (byte[] toHash) { byte[] data; using (MD5 md5Hash = MD5.Create ()) { data = md5Hash.ComputeHash (toHash); } StringBuilder sBuilder = new StringBuilder (); for (int i = 0; i < data.Length; i++) { sBuilder.Append (data[i].ToString ("x2")); } string hash = sBuilder.ToString (); if (s_verboseEnabled) { Debug.LogWarning ("VuforiaCloudController -> MD5Hash: " + hash); } return hash; }
I have to say that I took a look to an example project that is usng UniWeb and I'm trying to convert it to the WWW standard Unity class.
If I run the example everything will succed, but if I delete the image from the cloud and try the same with my script, it fails (authentication failed).
Comparing the 2 request parameters, I noticed the the MD5 ic completely different so that also the signature will be wrong.
Can someone please help me to figure out how and of what I need to calculate the MD5?
Thank you very much :-)
Upload a new target using Unity
Sounds like a general Unity / C# programming task ( MD5 encoding... )
But there is an example written in Java in the VWS samples, if you're interested:
https://developer.vuforia.com/resources/sample-apps/vuforia-web-services-api-java-implementation
Upload a new target using Unity
I'm definitely going to take a look to the example.
Thanks :-)
Upload a new target using Unity