JastinBall
JastinBall

Reputation: 893

Loading image from iphone in Unity3d

I send image path to unity using iOS Unity plugin. And in Unity I try to get this image using received path (I have no other idea how to send image from iphone to unity). The problem: I still can't get the image. WWW Error: The requested URL was not found on this server.

//Tried both "file:///..." and "file://..."
string path = "file://var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png" 

Texture texture;

IEnumerator WaitForRequest(WWW www) {
    yield return www;

    if (www.error == null) {
        texture = www.texture;
    }    
}

void Start() {
    WWW www = new WWW(path);
    StartCoroutine(WaitForRequest(www));
}

Upvotes: 3

Views: 8394

Answers (1)

Calvin
Calvin

Reputation: 4195

Make sure the file is there using

System.IO.File.Exists("/var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png") 

because your code looks correct.

Also, instead of hardcoding the path you should use Application.persistentDataPath.

string path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");

BTW, I think an absolute file url should always start with file:///.

Upvotes: 3

Related Questions