zhaoyang 2 years ago
parent
commit
f6dd6c6458

+ 33 - 13
GameClient/Assets/Game/HotUpdate/ServerProxy/PoemPhotoSProxy.cs

@@ -3,9 +3,11 @@ using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Net;
+using System.Net.Http;
 using ET;
 using FairyGUI;
 using GFGGame;
+using ICSharpCode.SharpZipLib.GZip;
 using UnityEngine;
 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();
+            //     }
+            // }
 
         }
         //保存成功后,添加图片至相册

+ 30 - 14
GameClient/Assets/Game/HotUpdate/Views/DressUp/PhotographSaveView.cs

@@ -74,31 +74,47 @@ namespace GFGGame
                 return;
             }
 
-            // Texture2D tex = this.viewData as Texture2D;
-            // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
 
             string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl((int)PictureType.jpg);
             if (rsp == null) return;
 
-            Timers.inst.StartCoroutine(PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes, async () =>
+            bool pushResult = await PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
+            if (!pushResult) return;
+
+            long addResult = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
+            if (addResult > 0)
             {
-                long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
+                List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
 
-                if (result > 0)
+                for (int i = 0; i < list.Count; i++)
                 {
-                    List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
-
-                    for (int i = 0; i < list.Count; i++)
+                    if (list[i].PictureId == addResult)
                     {
-                        if (list[i].PictureId == result)
-                        {
-                            list[i].Ntexture = new NTexture(tex);
+                        list[i].Ntexture = new NTexture(tex);
 
-                            break;
-                        }
+                        break;
                     }
                 }
-            }));
+            }
+            // Timers.inst.StartCoroutine(PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes, async () =>
+            // {
+            //     long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
+
+            //     if (result > 0)
+            //     {
+            //         List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
+
+            //         for (int i = 0; i < list.Count; i++)
+            //         {
+            //             if (list[i].PictureId == result)
+            //             {
+            //                 list[i].Ntexture = new NTexture(tex);
+
+            //                 break;
+            //             }
+            //         }
+            //     }
+            // }));
 
         }
     }