- Home /
How to use WWW to load Local files?
Hi guys, when I first thought of doing this, I thought there would be no problem but now I'm stuck for hours in this.
What kind of path should I provide to the WWW constructor?
It has to have "file://" as protocol?
Do I need to yield?
here is my current, not working, implementation:
public class loadwww : MonoBehaviour {
public Texture2D tex;
public WWW w;
void Start()
{
LoadTex();
}
void LoadTex ()
{
w = new WWW ("file://Users/Paulo/Desktop/img_2013_008_original.jpg");
}
void Update ()
{
if(w.isDone)
{
Debug.Log("done");
tex = w.texture;
}
}
}
And the error it's presenting:
You are trying to load data from a www stream which had the following error when downloading. Couldn't open file /Paulo/Desktop/img_2013_008_original.jpg UnityEngine.WWW:get_texture() loadwww:Update() (at Assets/MakeLy/Scripts/loadwww.cs:24)
ANSWER:
The root in OSX is /Users, so the correct URL is file:///Users/[...] with three / instead of only two.
Answer by Paulo-Henrique025 · Aug 17, 2013 at 03:52 PM
The root in OSX is /Users, so the correct URL is file:///Users/[...] with three / instead of only two.
Answer by ArkaneX · Aug 17, 2013 at 01:58 PM
You lack drive info in your URL. It probably has to be "file:///c://Users/......". And regarding 'yield' - yes - you should use WWW loading inside coroutine, like in this example.
Thank you for your answer, I'm using OSX and turns out the root folder is /Users, so the correct path is file:///Users/[...] with that third /. Thank you for effort anyway :)
I hope this will $$anonymous$$ch me not to assume that someone uses Windows :)
Answer by Joyrider · Aug 17, 2013 at 01:58 PM
You need to add your drive to the path: "file://c://Users/..."
Thank you for your answer, I'm using OSX and turns out the root folder is /Users, so the correct path is file:///Users/[...] with that third / .Thank you for effort anyway :)
Answer by EMR_1 · Aug 16, 2018 at 11:13 PM
I am loading an image stored to the local drive. The Application.persistentDataPath string to the file does not include the prepended "file://". Instead of just manually adjusting the string I am using UriBuilder to achieve the same result, perhaps with more portability:
String tFullPathName = Application.persistentDataPath + "/" + folderName + "/" + filename;
UriBuilder tURIBuilder = new UriBuilder( tFullPathName );
tURIBuilder.Scheme = "file"; // Uri.UriSchemeFile is not available when building for UWP (?). It is the string "file" so I just use the string here.
WWW tWWW = new WWW( tURIBuilder.ToString() );
Your answer
