Search Unity

DownloadHandlerFile on iOS 12.3/2018.3 not working

Discussion in 'Scripting' started by jokigenki, Jun 11, 2019.

  1. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    41
    Hi,

    I recently upgraded my iPad to iOS 12.3 and now it fails when trying to download files. It used to work fine, so I'm not sure what I can do other than write my own DownloadHandlerFile, which seems a bit redundant?

    I've tried using Unity 2018.3.14f1 and the code is the same as the UnityWebRequest DownloadHandlerFile example. I've verified that the folder exists and the file does not.

    I get the following error (note that it doesn't matter if it's an image, a binary file, a text file, an asset bundle, the result is the same):

    ArgumentException: Failed to create file /var/mobile/Containers/Data/Application/XXX/Documents/cache/image.png at UnityEngine.Networking.DownloadHandlerFile.InternalCreateVFS (System.String path) [0x00000] in <00000000000000000000000000000000>:0
    at ContentCache+<DoDownload>d__39.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
    at ContentCache.DownloadFile (System.String url, System.String pathToSaveImage) [0x00000] in <00000000000000000000000000000000>:0
    at ContentCache.DownloadFileFromKey (System.String localKey, System.Action callback) [0x00000] in <00000000000000000000000000000000>:0
    at ContentCache.DownloadFilesKeysVersion (System.Collections.Generic.List`1[T] cKeysList, System.Action callback) [0x00000] in <00000000000000000000000000000000>:0
    at ContentCache+<BuildCacheFromFirebaseData>d__17.MoveNext () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0
    at UnityMainThreadDispatcher.Update () [0x00000] in <00000000000000000000000000000000>:0
    ContentCache:DownloadFile(String, String)
     
  2. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    41
    Just tried compiling with 2019.1.6f1 and got the same result. Is there some permission I need to set?
     
  3. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Are you writing to a file inside Application.persistentDataPath?
     
  4. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    41
    Yes, the full path is: /var/mobile/Containers/Data/Application/XXX/Documents/cache/image.png (XXX is the application name)
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,736
    Can you show the code how you run UnityWebRequest?
     
  6. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    41
    Hi,

    The code I'm calling is:

    Code (CSharp):
    1. public IPromise DownloadFile (string url, string pathToSaveImage)
    2.     {
    3.         _filesToDownload++;
    4.         if (_filesToDownload > 0) AppFlowManager.Instance.ShowLoadingSpinner (L10nId.Misc_Loading);
    5.         Promise promise = new Promise ();
    6.         StartCoroutine (_DownloadFile (url, pathToSaveImage, promise));
    7.  
    8.         return promise;
    9.     }
    10.  
    11.     private IEnumerator _DownloadFile (string url, string savePath, Promise promise)
    12.     {
    13.         if (!Directory.Exists (Path.GetDirectoryName (savePath)))
    14.         {
    15.             Directory.CreateDirectory (Path.GetDirectoryName (savePath));
    16.         }
    17.  
    18.         Dedbugs.Log ($"Make web request for {url}", Dedbugs.Caching);
    19.  
    20.         UnityWebRequest request = UnityWebRequest.Get (url);
    21.         request.downloadHandler = new DownloadHandlerFile (savePath);
    22.         request.SendWebRequest ();
    23.  
    24.         while (!request.isDone)
    25.         {
    26.             yield return null;
    27.         }
    28.  
    29.         //Check if we managed to send
    30.         if (string.IsNullOrEmpty (request.error))
    31.         {
    32.             Dedbugs.Log ($"Download file Success from {url} to {savePath}", Dedbugs.Caching);
    33.             _filesToDownload--;
    34.             promise.Resolve ();
    35.         }
    36.         else
    37.         {
    38.             Dedbugs.Log ($"Download file Error: {request.error}", Dedbugs.CachingErrors);
    39.             _filesToDownload--;
    40.             promise.Reject (new ApplicationException (request.error));
    41.         }
    42.     }
    43.  
    The error occurs on the line: request.downloadHandler = new DownloadHandlerFile (savePath);
     
    avin-kiseki likes this.
  7. madhurg

    madhurg

    Joined:
    Jun 22, 2020
    Posts:
    3
    Bump
    @Aurimas-Cernius any help here. I am also getting this issue. I am on Unity 2018.4.23f1
     
  8. devmadhurg

    devmadhurg

    Joined:
    May 19, 2020
    Posts:
    1
    Yes.
     
  9. gerrans

    gerrans

    Joined:
    Feb 19, 2019
    Posts:
    1
  10. jokigenki

    jokigenki

    Joined:
    Jul 19, 2014
    Posts:
    41
    It's been a while since I worked on this bit of code, but checking back on it, it hasn't changed, so I don't think it was an issue with the C# code, although this was 2 years ago, so I can't really remember. Sorry I can't be of more help :(
     
  11. DirtyFred

    DirtyFred

    Joined:
    May 17, 2014
    Posts:
    29
    I have the same issue. Did anyone find a solution? I get this error randomly and i cant even the " yield return loader.SendWebRequest();" into a try catch....
     
  12. Sxxshkv

    Sxxshkv

    Joined:
    Jun 26, 2020
    Posts:
    1
    Hello everybody! I have encountered the same problem, but it is not a fact that the cause of your occurrence is the same.
    I tried to download and burn the same file twice, and that's why I got this error.