Hyluss

[Unity] partial downloads using UnityWebRequest

May 6th, 2019
222
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. IEnumerator PartlyDownload()
  2.     {
  3.         string url = connectionConfig.ImagesNameListEndpoint;
  4.  
  5.         Debug.Log(Application.persistentDataPath);
  6.         string vidSavePath = Path.Combine(Application.persistentDataPath, "list");
  7.         vidSavePath = Path.Combine(vidSavePath, "MyList.txt");
  8.  
  9.         //Create Directory if it does not exist
  10.         if (!Directory.Exists(Path.GetDirectoryName(vidSavePath)))
  11.         {
  12.             Directory.CreateDirectory(Path.GetDirectoryName(vidSavePath));
  13.         }
  14.  
  15.         DownloadHandler downloadHandler = new DownloadHandlerFile(vidSavePath);
  16.         var download = new UnityWebRequest(url, UnityWebRequest.kHttpVerbGET, downloadHandler, null);
  17.         int resumeOffset = 131;
  18.         var rangeHeader = "bytes=" + resumeOffset + "-";
  19.         download.SetRequestHeader("Range", rangeHeader);
  20.  
  21.         yield return download.SendWebRequest();
  22.  
  23.         if (download.isNetworkError || download.isHttpError)
  24.             Debug.Log(download.error);
  25.         else
  26.             Debug.Log("Success");
  27.  
  28.     }
Comments
  • User was banned
Add Comment
Please, Sign In to add comment