- Home /
Loading an image from streamingassets fails every time on Android
I am trying to load an image file from streamingassets. I figured a potential workaround was to write the image file to the persistentdatapath as that seemed to help others. I have checked every forum post and attempted to implement the solution, to no success. I am looking for any solution, and I hope this isnt a duplicate. I have tried for days to get this to work, unsuccessfully. I can verify on my computer filesystem that I am able to write the file to the persistentdatapath. My only theory is that maybe my usb debugging settings are not allowing access or something. Here's my code, I hope someone can help.
void Start () {
WWW reader = new WWW(Application.streamingAssetsPath+"/bundle.jpg");
while (!reader.isDone) { }
string realPath = Application.persistentDataPath + "/bundle.jpg";
System.IO.File.WriteAllBytes(realPath, reader.bytes);
dbPath = realPath;
WWW www = new WWW(dbPath);
while (!www.isDone) { }
Texture2D tex = www.texture;
GameObject.Find("FilePath").GetComponent<Text>().text = Application.streamingAssetsPath;
GameObject.Find("Picture").GetComponent<Image>().sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(.5f, .5f));
}
Thanks in advance.
Answer by Cdawg_1999 · Sep 16, 2017 at 12:35 AM
I got this to work by moving all files I want into the persistent data path. The issue I was having was not including file:// on the call from persistent data.
Your answer
Follow this Question
Related Questions
Save an image to PersistentDataPath then access it again 1 Answer
I can't figure out how to use www to copy a file / very confused about porting to android... 0 Answers
Android Persistent Data loading fails 1 Answer
how do you correctly copy a jpg file from streaming assets folder using www? 1 Answer