Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Samshosho · Jun 05, 2011 at 09:38 PM · savefiledownloadurlbyte

Save a file from a URL to documents folder then use it doesn't work

Here is what i have in Unity /////////////////////////////////////// var url = "http://domain/Movie/TestingMovie.mov"; www = new WWW(url); var progress1 = www;

print(progress1.progress);

while (!progress1.isDone) yield;

var fileName : String = Application.persistentDataPath + "/" + "TestingMovie.mov"; print(" progress1.bytes.length = "+progress1.bytes.length);

System.IO.File.WriteAllBytes(fileName, progress1.bytes);

Debug.Log("Cache saved: " + fileName); print("file download is done");

yield WaitForEndOfFrame();

if (System.IO.File.Exists("file://" + Application.persistentDataPath + "/TestingMovie.mov")) { print(" file does exist"); } else print(" file does not exist");

iPhoneUtils.PlayMovieURL(("file://" + Application.persistentDataPath + "TestingMovie.mov"), Color.black, iPhoneMovieControlMode.Full);

This is what i have output in Xcode /////////////////////////////////////////////////// (Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

progress1.bytes.length = 63708

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

Cache saved: /var/mobile/Applications/BAD0E1A0-FD53-4033-915B-D99C718173B3/Documents/TestingMovie.mov

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file download is done

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file does not exist

////////////////////////////////////////////////

Not sure what's going on, even though the correct bytes.length is showing, then i ask it to write all bytes to the file name, but still the files does not exist, thus it does not play!

Something i am missing ?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chris D · Jun 05, 2011 at 09:51 PM 0
Share

Please format your code so people can read it. Use the "1001011" button after highlighting your code portion.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Samshosho · Jun 06, 2011 at 09:37 AM

here is the code nicely formated...

Here is what i have in Unity ///////////////////////////////////////

 var url = "http://domain/Movie/TestingMovie.mov"; www = new 
 
         WWW(url); var progress1 = www;
         
         print(progress1.progress);
         
         while (!progress1.isDone) yield;
         
         var fileName : String = Application.persistentDataPath + "/" + "TestingMovie.mov"; 
     ``print(" progress1.bytes.length = "+progress1.bytes.length);
         
         System.IO.File.WriteAllBytes(fileName, progress1.bytes);
         
         Debug.Log("Cache saved: " + fileName); 
     ``print("file download is done");
         
         yield WaitForEndOfFrame();
         
         if (System.IO.File.Exists("file://" + Application.persistentDataPath + "/TestingMovie.mov")) { 
     ``print(" file does exist"); 
      ``} 
         else 
     ``print(" file does not exist");
         
         iPhoneUtils.PlayMovieURL(("file://" + Application.persistentDataPath + "TestingMovie.mov")
 `    `, Color.black, iPhoneMovieControlMode.Full);

This is what i have output in Xcode /////////////////////////////////////////////////// (Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

progress1.bytes.length = 63708

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

Cache saved: /var/mobile/Applications/BAD0E1A0-FD53-4033-915B-D99C718173B3/Documents/TestingMovie.mov

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file download is done

(Filename: /Applications/buildAgent/work/6bc5f79e0a4296d6/Projects/../Runtime/Export/Generated/BaseClass.cpp Line: 2505)

file does not exist

////////////////////////////////////////////////

Not sure what's going on, even though the correct bytes.length is showing, then i ask it to write all bytes to the file name, but still the files does not exist, thus it does not play!

Something i am missing

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by sloopidoopi · Mar 23, 2013 at 04:38 PM

Hi,

the problem is the System.IO.File.Exists("

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by bacalao · Feb 05, 2019 at 06:12 PM

 void Start()
     {
         StartCoroutine(savefile("http://www.any.com/anything.jpg", "myfile.jpg", Application.dataPath));
     }
  
     IEnumerator savefile(string myurl, string mytargetname, string folder)
     {
         string FileFullName = folder + "/" + mytargetname;
         if (System.IO.File.Exists(FileFullName))
         {
             print(mytargetname + " does exist");
             yield break;
         }
         else { print(mytargetname + " does not exist, downloading.."); }
  
         var www = new WWW(myurl);
  
         var progress1 = www;
  
         print(progress1.progress);
  
         while (!progress1.isDone) yield return null;
  
         print(" progress1.bytes.length = " + progress1.bytes.Length);
  
         System.IO.File.WriteAllBytes(FileFullName, progress1.bytes);
  
         Debug.Log("Cache saved: " + FileFullName);
         print("file download is done");
  
         yield break;
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Save Unfinished Download 0 Answers

Download Links from GUI 2 Answers

Saving Local Data through WWW 1 Answer

Unity Blackberry - Save file on device 0 Answers

How to Retrieve List of Files on FTP Server 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges