|
@@ -3,9 +3,11 @@ using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net;
|
|
|
|
+using System.Net.Http;
|
|
using ET;
|
|
using ET;
|
|
using FairyGUI;
|
|
using FairyGUI;
|
|
using GFGGame;
|
|
using GFGGame;
|
|
|
|
+using ICSharpCode.SharpZipLib.GZip;
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
@@ -71,22 +73,40 @@ namespace GFGGame
|
|
}
|
|
}
|
|
|
|
|
|
//将图片上传到华为云
|
|
//将图片上传到华为云
|
|
- public static IEnumerator PushToHWCloud(string signUrl, byte[] buffer, Action callback)
|
|
|
|
|
|
+ public static async ETTask<bool> PushToHWCloud(string signUrl, byte[] buffer)
|
|
{
|
|
{
|
|
- using (UnityWebRequest www = UnityWebRequest.Put(signUrl, buffer))
|
|
|
|
- {
|
|
|
|
- yield return www.SendWebRequest();
|
|
|
|
|
|
|
|
- if (www.result != UnityWebRequest.Result.Success)
|
|
|
|
- {
|
|
|
|
- Debug.Log("上传失败:" + www.error);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- Debug.Log("上传成功");
|
|
|
|
- callback?.Invoke();
|
|
|
|
- }
|
|
|
|
|
|
+ HttpContent content = new ByteArrayContent(buffer);
|
|
|
|
+ HttpClient httpClient = new HttpClient(new HttpClientHandler() { UseCookies = false });
|
|
|
|
+ HttpResponseMessage response = await httpClient.PutAsync(signUrl, content);
|
|
|
|
+ response.EnsureSuccessStatusCode();
|
|
|
|
+ await response.Content.ReadAsStreamAsync();
|
|
|
|
+ if (response.StatusCode != HttpStatusCode.OK)
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
+ // GZipInputStream inputStream = new GZipInputStream(await response.Content.ReadAsStreamAsync());
|
|
|
|
+
|
|
|
|
+ // var responseBody = new StreamReader(inputStream).ReadToEnd();
|
|
|
|
+
|
|
|
|
+ // using (UnityWebRequest www = UnityWebRequest.Put(signUrl, buffer))
|
|
|
|
+ // {
|
|
|
|
+ // yield return www.SendWebRequest();
|
|
|
|
+
|
|
|
|
+ // if (www.result != UnityWebRequest.Result.Success)
|
|
|
|
+ // {
|
|
|
|
+ // Debug.Log("上传失败:" + www.error);
|
|
|
|
+ // }
|
|
|
|
+ // else
|
|
|
|
+ // {
|
|
|
|
+ // Debug.Log("上传成功");
|
|
|
|
+ // callback?.Invoke();
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
}
|
|
//保存成功后,添加图片至相册
|
|
//保存成功后,添加图片至相册
|