I tried to download and write a new file after deleting older one. This script downloads and writes perfectly on standalone but it doesnt download new file but it logs instantly old file's size "Debug.Log(www1.size.ToString());" on ipad2 and iphone4. I tried it with C# too, same result. with Application.temporaryCachePath, same result. .Net 2.0 is full, isnt subset. Code (csharp): import System; import System.IO; var url1 = "http://www.myweb.net/myfile.mp4"; (.mp3 , .dat , .png ... tested file formats); var www1 : WWW; function Download1 () { if(www1!=null){www1=null; Debug.Log("NULL");} www1 = new WWW (url1); yield www1; if(File.Exists(Application.persistentDataPath+"/myfile.mp4")) { File.Delete(Application.persistentDataPath+"/myfile.mp4"); if(!File.Exists(Application.persistentDataPath+"/myfile.mp4")) {Debug.Log("DELETED");} } File.WriteAllBytes(Application.persistentDataPath+"/myfile.mp4", www1.bytes); Debug.Log(www1.size.ToString()); } function OnGUI () { if (GUI.Button (Rect (10,10,150,100), "Download1")) { Download1 (); } } Where is the problem and how can i fix that? Thanks.
just a guess, i had this when saving "screenshots". There the capturing and writing was asynchronous. It took about 1 second to write the file. Thus, you could try someting with a delay or coroutine to check when the file actually got written, if at all.
I tried download 2 files with coroutine. This works for bigger sized file now but lower sized file again old one. Code (csharp): void Start() { string myurl = "http://www.myweb.net/"; string myfile = "myFile"; StartCoroutine(Download(myurl, myfile + ".xml")); StartCoroutine(Download(myurl, myfile + ".mp4")); } IEnumerator Download(string url, string filename) { string remoteFile = url + "/" + filename; string localFile = Application.persistentDataPath + "/" + filename; if (System.IO.File.Exists(localFile)) { System.IO.File.Delete(localFile); } WWW wwwfile = new WWW(remoteFile); yield return wwwfile; System.IO.File.WriteAllBytes(localFile, wwwfile.bytes); if (System.IO.File.Exists(localFile)) { Debug.Log(" file does exist"); } else { Debug.Log(" file does not exist"); } Debug.Log(wwwfile.size.ToString()); }
That's not what I meant. You should have delay after download and after write. For simplicity sake make something like waitforseconds(5) after you start writing. When I did my screenshot stuff, I used only one file name "screenshot.png". After saving I wanted it to show up in an email composer immediately. But after 1. Save there was of course always such a file. And in the mail composer the last shot was loaded, not the one I just took. So in the end I did this: 1. Check if there is a file. If there is, delete it. 2. Make the new shot and save. This is asynchrounous. 3. Start a coroutine which checks for the file every 0.5 seconds. 4. At some time the new image should be written, coroutine will find it now, and start the mail composer things.