-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerTest_v1.cs
More file actions
50 lines (43 loc) · 1.51 KB
/
ServerTest_v1.cs
File metadata and controls
50 lines (43 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class ServerTest_v1 : MonoBehaviour
{
private string setURL = "http://www.bhamxr.com:1234/upload-manager.php";
//public Texture2D tex = new Texture2D(2,2);
private void Update()
{
if (Input.GetKeyDown(KeyCode.Z))
{
//byte[] byteArray = File.ReadAllBytes(@"D:\SampleImage.png");
byte[] byteArray = File.ReadAllBytes(@"C:\Users\danhq\Pictures\gblob.png");
string str = Encoding.UTF8.GetString(byteArray);
Debug.Log("Image loaded!!!");
Debug.Log(str);
//You can then load it to a texture
//Texture2D tex = new Texture2D(2, 2);
//tex.LoadImage(byteArray);
StartCoroutine(UploadImage(byteArray));
//StartCoroutine(UploadImage(str));
}
}
//IEnumerator UploadImage(string imageBytes)
private IEnumerator UploadImage(byte[] imageBytes)
{
WWWForm form = new WWWForm();
form.AddBinaryData("photo", imageBytes, "gblob.png", "image/png");
//form.AddField("postStartScr", imageBytes);
UnityWebRequest www = UnityWebRequest.Post(setURL, form);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Image uploaded!!!");
}
}
}