Im trying to upload a png to my webservice using WWW and WWWForm, however the data is not reaching the webservice. Here’s my code and the outputs.
private IEnumerator UploadAvatar(string id, Texture2D pic)
{
if (id != null && pic != null)
{
Debug.Log("Starting Upload");
WWWForm form = new WWWForm();
byte[] bytes = pic.EncodeToPNG();
string data = string.Empty;
for (int i = 0; i < bytes.Length; ++i)
data += bytes *+ ".";*
Debug.Log(data);
form.AddBinaryData(“pic”, bytes);
byte[] newData = form.data;
System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
Debug.Log(enc.GetString(newData));
string url = APIManager.GetInstance().serverLocation + “/uploadavatar.php”;
Debug.Log(url);
WWW web = new WWW(url, form);
yield return web;
Debug.Log(web.error + "
" + web.text);
}
}
And the output for the byte array of the texture
137 80 78 71 13 10 26 10 0 0 0 13 73 72 68 82 0 0 0 30 0 0 0 30 8 6 0 0 0 59 48 174 162 0 0 6 68 73 68 65 84 72 13 189 86 9 76 83 103 28 127 71 91 90 90 232 205 85 192 2 69 203 17 14 185 4 1 229 240 158 153 23 196 136 215 230 112 139 58 162 110 115 78 205 204 150 44 219 146 145 225 208 45 186 44 115 196 40 226 57 81 97 42 106 16 68 64 101 4 43 45 227 150 150 114 148 150 210 82 94 11 175 251 30 177 181 148 22 49 51 251 39 95 222 255 252 253 222 119 127 176 217 108 134 246 66 51 11 142 227 48 104 8 200 133 81 20 157 64 16 196 108 95 81 96 239 120 141 77 122 77 124 50 12 136 80 173 86 203 208 77 76 208 221 72 164 81 38 147 169 1 129 105 228 179 193 178 228 204 134 24 6 201 36 229 208 144 223 168 217 28 131 185 186 54 1 226 70 224 27 183 128 16 223 153 70 205 209 104 32 182 197 206 244 103 109 109 124 133 86 187 12 67 41 115 245 122 188 15 228 77 56 203 157 173 127 54 196 168 70 175 143 34 185 177 18 91 159 182 149 70 136 4 61 0 252 63 13 51 241 115 175 35 134 165 82 105 32 236 198 252 66 118 187 190 110 203 186 197 143 102 219 163 215 229 205 56 199 61 61 61 212 206 129 129 77 186 199 93 221 185 251 54 255 0 192 108 123 74 146 72 36 238 192 231 71 163 209 112 24 134 251 3 2 2 212 192 38 230 30 7 109 70 153 145 184 173 171 43 106 4 166 103 101 237 219 28 5 80 38 231 181 169 169 41 112 24 134 87 211 89 236 165 178 78 181 108 253 183 167 87 60 76 8 173 161 96 38 92 154 181 228 94 124 124 72 43 166 86 55 249 248 248 24 64 141 237 143 78 249 145 153 136 17 170 167 231 193 209 134 142 221 160 194 4 26 252 160 190 62 157 225 45 248 44 112 79 62 185 44 125 254 137 29 121 57 87 160 85 201 251 23 189 132 108 109 109 117 225 210 104 232 153 194 146 29 97 75 22 22 71 71 139 6 166 176 217 24 176 179 3 68 163 209 176 174 149 86 215 110 221 178 42 20 228 79 148 86 87 239 98 94 173 127 15 54 26 11 83 142 29 40 178 193 112 168 254 116 234 106 102 120 140 168 35 61 38 188 205 209 118 114 218 227 251 149 149 25 58 8 121 2 80 241 198 198 70 1 197 133 153 71 26 51 126 149 84 120 224 220 31 71 143 34 38 241 130 119 34 254 254 231 227 113 20 101 55 206 225 159 15 15 9 62 157 146 26 109 237 97 222 206 53 119 64 45 249 66 73 9 90 144 157 61 109 251 57 93 213 220 160 160 213 190 93 74 41 40 70 186 70 70 190 79 253 180 208 164 224 48 111 23 254 122 101 239 136 56 201 24 29 39 62 212 147 17 86 4 173 141 255 32 44 97 46 157 42 228 150 23 23 156 185 12 242 93 64 179 136 41 43 59 219 225 66 115 70 12 70 212 56 220 237 199 185 11 230 141 179 44 49 49 235 105 120 224 165 64 197 192 118 23 30 51 159 100 208 22 73 202 170 206 141 141 226 253 90 221 132 38 53 42 234 155 57 84 234 74 65 122 68 229 201 226 178 122 192 106 139 235 112 129 217 38 16 71 227 43 161 210 50 131 219 251 230 155 76 38 215 243 55 170 148 102 4 30 16 246 169 115 56 60 150 158 230 225 25 26 187 110 233 15 107 51 147 202 135 113 168 225 246 145 194 131 30 30 30 253 41 17 17 199 67 194 252 207 254 249 245 201 3 175 128 28 107 22 226 201 243 216 38 197 172 239 122 81 192 27 210 198 26 12 6 178 155 59 195 93 208 171 90 194 192 198 196 96 178 204 203 82 162 227 183 121 243 73 123 168 46 80 65 90 60 203 59 119 253 209 71 187 190 203 3 245 227 33 94 30 199 199 50 227 86 40 20 10 87 27 188 105 170 133 216 44 151 203 137 195 192 98 67 28 58 181 162 55 123 233 187 106 179 217 47 45 102 222 120 100 115 199 34 178 193 8 135 6 248 186 179 104 84 56 4 92 167 62 160 32 6 199 161 100 63 47 132 110 194 182 19 232 124 62 95 231 205 32 149 150 93 169 74 37 108 103 98 37 162 80 40 100 157 78 199 3 137 147 67 46 12 8 232 117 231 81 85 237 207 187 195 174 87 215 52 63 77 8 103 208 12 24 244 252 82 5 164 55 141 67 151 65 154 10 36 211 65 35 131 38 217 144 233 45 27 28 116 3 42 196 69 209 18 127 165 234 115 66 119 38 86 98 112 193 143 74 219 218 132 96 49 81 136 100 95 95 223 49 165 68 178 71 16 44 202 231 243 56 18 255 83 71 208 179 57 203 41 158 170 97 232 126 237 115 104 24 129 161 94 24 134 90 64 83 97 216 196 130 249 98 87 62 2 156 64 216 108 246 168 105 99 134 195 213 76 196 9 177 18 115 56 156 17 26 151 11 41 53 154 68 224 159 220 223 217 27 54 220 209 98 67 53 16 236 186 83 174 25 86 39 110 91 169 143 59 252 62 244 209 194 112 136 15 146 36 8 2 93 71 81 168 65 46 239 149 254 114 177 6 96 104 9 80 240 90 209 43 234 164 86 108 194 103 47 182 65 115 152 175 239 99 142 159 31 90 81 89 185 177 179 179 147 216 143 166 80 54 59 123 80 209 250 155 63 155 201 102 185 210 25 96 111 224 16 153 12 17 11 162 13 180 42 153 76 37 20 8 216 153 229 181 34 11 56 120 177 208 49 22 99 212 98 59 250 218 159 92 120 168 167 231 61 240 184 74 149 201 100 187 123 21 138 27 129 65 65 47 188 189 189 247 151 223 186 85 210 211 209 177 53 49 51 51 165 3 69 73 47 250 251 123 187 107 107 235 88 243 230 137 135 138 239 106 130 139 14 229 88 152 117 70 35 79 216 208 130 65 107 211 29 113 78 250 236 137 9 39 46 246 242 122 48 170 208 140 140 51 201 95 54 183 182 94 211 143 140 244 133 137 197 207 120 108 246 33 101 123 187 39 134 97 92 165 193 176 60 59 55 119 83 243 145 19 79 120 31 110 204 19 137 252 48 43 11 142 187 113 215 36 31 182 218 14 20 167 151 4 145 91 241 160 113 110 175 114 48 213 95 44 72 115 119 163 210 204 184 217 3 165 144 177 113 28 87 25 142 93 112 55 226 240 181 180 31 247 255 108 139 11 166 136 90 37 149 239 78 22 11 78 8 133 194 49 34 246 70 151 4 81 144 145 18 217 2 62 68 251 253 210 205 135 17 8 142 140 153 112 99 168 135 27 247 175 197 249 159 232 136 28 59 129 113 38 51 120 184 255 153 70 184 124 225 36 169 93 220 106 58 26 106 107 208 70 153 88 191 50 169 225 165 221 108 227 159 162 130 211 138 86 118 179 38 41 46 57 236 226 148 128 3 99 182 196 14 74 167 185 72 45 50 53 146 16 23 89 23 43 22 13 77 139 218 57 108 183 147 93 232 141 205 113 132 97 102 199 70 138 136 55 183 195 27 201 22 241 109 18 35 169 113 225 114 0 62 227 137 101 33 159 92 213 22 227 255 252 190 205 30 191 209 127 255 11 25 179 93 217 17 96 247 125 0 0 0 0 73 69 78 68 174 66 96 130
UnityEngine.Debug:Log(Object)
c__Iterator2:MoveNext() (at Assets/Scripts/Entourage.cs:81)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Entourage:OnAvatarPictureCreated(String, Texture2D) (at Assets/Scripts/Entourage.cs:69)
Entourage:OnGUI() (at Assets/Scripts/Entourage.cs:59)
And this is the output after converting the WWWForm.data to a string:
–8Q8exXEoFDvoNoSfIi9ome0otE8z5ObiyVWkoaQy
Content-Type: image/png
Content-disposition: form-data; name=“pic”; filename=“pic.png”
�PNG
UnityEngine.Debug:Log(Object)
c__Iterator2:MoveNext() (at Assets/Scripts/Entourage.cs:85)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
Entourage:OnAvatarPictureCreated(String, Texture2D) (at Assets/Scripts/Entourage.cs:69)
Entourage:OnGUI() (at Assets/Scripts/Entourage.cs:59)
The webservice is just printing the arrays on the screen for testing.
But here’s that code:
<?php*
*print($GLOBALS);*
*$profile = $_POST['pic'];*
*echo $profile;*
*?>
And the response back in unity:
Array
Any help would be greatly appreciated.