Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

UnityWebRequest for local files on Android - failure

Discussion in 'Scripting' started by KeirREA, Nov 18, 2016.

  1. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    719
    I used uriBuilder:

    Code (CSharp):
    1.  UriBuilder uriBuilder = new UriBuilder(filePath);
    2.  
    3.         using (UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(uriBuilder.Uri, false))
    4.         {
    5. }
    It's working with most textures as I unpack them and extract them first time to persistentDataPath...but not with others. Error I've got:

    No Asset Found At Path /storage/pathgoeshereetcetc/texture.png

    Apparently Application.persistentDataPath is just giving me: /storage/ etc etc.... strange....but the odd thing is it's working with music files and all kinds of other things, and even textures, just not textures at a particular place in the scene when it's starting up.
     
  2. astracat111

    astracat111

    Joined:
    Sep 21, 2016
    Posts:
    719
    Also, what fixed it in my case was doing

    filePath = filePath.Replace("\\","/");

    Android, Linux, Unix, Mac from what I understand everything other than windows won't accept a backslash, it's all forward slash for directories
     
  3. Tural-Muslim

    Tural-Muslim

    Joined:
    Oct 24, 2019
    Posts:
    31
    How can I translate this "UnityWebRequest"? :(


    Code (CSharp):
    1. private IEnumerator ShareFile()
    2.     {
    3.         WWW www = new WWW(Application.streamingAssetsPath + "/" + mFileName);
    4.         yield return www;
    5.         string filePath = Path.Combine(Application.persistentDataPath, mFileName);
    6.         File.WriteAllBytes(filePath, www.bytes);
    7.  
    8.         new NativeShare().AddFile(filePath).Share();
    9.     }
     
  4. LordVise

    LordVise

    Joined:
    Aug 1, 2020
    Posts:
    7
    @astracat111 Fantastic!
    "UriBuilder uriBuilder = new UriBuilder(filePath);
    ..... UnityWebRequestMultimedia.GetAudioClip(uriBuilder.Uri .....
    "
    did the trick. I have spent weeks trying to get this to work on Android. So many people have posted about this but the posts all seem to be out of date.
    Thank you so much for taking the time to post a working solution for Unity's current version (2021.3)