UnityWebRequest and local area network

Hello,

I’m in enterprise environnement for develop a solution on Unity 3D. My document are in local area network (on a NAS). And I want to read image in this folder and load it in my solution.

Here a sample of what I want do :

// string file = "file://C:/Medias/m_7.jpg"; => WORK
string file = "file://192.168.1.150/MyDoc/Medias/m_7.jpg"; // => NOT WORK

Texture tex = null;

Uri uri = new Uri(file);

using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(uri))
{
    yield return uwr.SendWebRequest();
    if (string.IsNullOrEmpty(uwr.error))
    {
        tex = DownloadHandlerTexture.GetContent(uwr);
    }
    else
    {
        Debug.Log(uwr.error);
    }

}

The adress server is a sample but look like of what I have here.

I can load texture on local drive or on the internet with “UnityWebRequestTexture.GetTexture()” but the method seems not work when the file is on the local network.

Did I miss something ?

I can’t really comment on the LAN aspect specifically, but from what I recall about issues with “file://” I’ve seen around previously, in Windows you actually need to use three /// slashes- two will work in some instances but not others. Can you just quickly verify if that fixes it or not? Hopefully someone with more familiarity with this issue than I will be by soon, if not.

Thank you,
I test with three slashes and also on a mac or Android I want load resources with this way… If someone has an idea my previous code was based on WWW which is obsolete now.

The part about three slashes is not correct. The slashes are required on Windows for local files, for network stuff two is actually correct.
file protocol for non-local files is in general not well defined. Try using computer name instead of IP address. Another thing you can try is smb protocol instead of file, should work for Windows/Samba shares, but be aware that this is not supported across all platforms (should be ok on desktops though).

1 Like

Thank you,

We find the problem we must put a 4rd slash :

“file:////192.168.1.150/MyDoc/Medias/m_7.jpg”

It’s works !!

smb and computer name doesn’t work.

Thanks for the help !

1 Like

Now when you wrote it, I did remember it: the conforming URI actually requires file slashes, four is a “relaxed version” :slight_smile:
Basically it’s like this:

  • you have an absolute path, which is \192.168.1.150\MyDoc.…
  • you replace backslashes with forward slashes, so you get //192.168.1.150/MyDoc/
  • now you have to make it to the absolute path in a UNIX form, which means prepending another slash (because “//192.168.1.150” is a directory name in this case), so it’s now ///192.168.1.150/MyDoc/…
  • finally you prepend the file:// shame to it: file://///192.168.1.150/MyDoc/…

Looks very weird, but that’s what it is. Though I think our code supports the relaced form with four slashes just fine (added along with local files with just two slashes due to a very common “mistake”).

1 Like

how to get all the images in that folder

how to get the all images from that folder?

Only by requesting them one by one. There is no support for file listing.

there is nothing like
var info = new DirectoryInfo(path);
FileInfo[ ] fis = info.GetFiles();

this