Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 edd21101 · Dec 29, 2014 at 05:09 PM · androidmobilefilesreplace

How can I download a file (.jpg) and store it?

Hello.

I've been looking documentation and it's not clear to me. I've been trying to use "fileUtil.replacefile" with no results.

I need to download a file and store it locally so it will work without internet connection. So, the downloaded file should replace an asset.

I've been trying it for a week and I ran out of ideas, plase help! :(

Thank you so much in advance.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Paulius-Liekis · Dec 30, 2014 at 04:04 PM

You can not replace an asset by just downloading an image from the internet (well unless we're taking about Editor space, but I doubt that we are). You can download image using WWW class, and then store it anywhere on disk using something like File.WriteAllBytes(www.bytes). Later you can load the same image form local disk using same WWW class. Use WWW.texture to access the downloaded image (i.e. for putting it on a material and so on)

Comment
Add comment · Show 5 · 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 edd21101 · Dec 30, 2014 at 04:38 PM 0
Share

Thank you so much, But I have a question. This is only for windows? (.exe)... There's a way to do that for mobile devices? (.apk , .ipa)

:)

avatar image Paulius-Liekis · Dec 31, 2014 at 10:02 AM 0
Share

You can do the same thing for mobiles, but you have to store your own files under Application.persistenDataPath.

avatar image Landern · Dec 31, 2014 at 10:42 AM 0
Share

@edd21101, to futher what Paulius Liekis stated, you need to request the permission to be able to write on the device as well.

avatar image edd21101 · Jan 02, 2015 at 03:23 PM 0
Share

Thanks a lot @paulius I'll try it.... And thank you too @Landern... I didn't noticed that either. This is really helpful.

avatar image edd21101 · Jan 02, 2015 at 10:21 PM 0
Share

Worked like a charm!... Thank you so much to both of you. I had some troubles to make it in Javascript and I had to add some things to make it work... Was not that easy, but the comment was the key to the solution.

I'll leave the code I used here for anyone who needs it in the future. (Sorry about the comments in Spanish, that's my native language and it's easier for me to understand my own code.)

 // I$$anonymous$$PORTO CLASES PARA USAR FIL$$anonymous$$
 import System.IO;
 
 var texLocalPoner : Texture;
 
 var url = "http://xxxxxx.com/xxx/image01.jpg";
 
 
 function Start () {
 
     // PONGO EL DIRECTORIO PERSISTENTE EN UNA VARIABLE
     var dir = Application.persistentDataPath;
     
 
     //CO$$anonymous$$IENZO POR PONER LA TEXTURA QUE YA SE ENCUENTRE EN EL DISCO:
     
     //LLA$$anonymous$$O EL DIRECTORIO CON LA CLASE WWW
 
     var texturaLocal : WWW = new WWW("file://"+dir+"/image01.jpg");
     
     //ESPERO A QUE CARGUE
     
     yield texturaLocal;
     
     //LA VUELVO TEXTURA
     
     texLocalPoner = texturaLocal.texture;
     
     //LA PONGO EN EL $$anonymous$$ATERIAL
     
     renderer.material.mainTexture = texLocalPoner;
     
     yield CargarImg();
     reemplazarImg();
 
     
 }
 
 
 //CREA$$anonymous$$OS UNA FUNCION QUE BAJE LA I$$anonymous$$AGEN Y LA ASIGNE A UNA VARIABLE PARA USARLA LUEGO
 
 function CargarImg(){    
 
     var www : WWW = new WWW (url);
 
     yield www;
     
     // AL$$anonymous$$ACENA$$anonymous$$OS LA TEXTURA DESCARGADA EN UN ARRAY DE BYTES
  
     bytesTextura = www.bytes;
     
     //AL$$anonymous$$ACENA$$anonymous$$OS TEXTURA DESCARGADA EN DIRECTORIO PERSISTENTE
     
     File.WriteAllBytes(Application.persistentDataPath + "/image01.jpg",bytesTextura);
     
     
     texLocalPoner = www.texture;
     
     
 }
 
 
 // CREO UNA FUNCION QUE REE$$anonymous$$PLAZARÁ LA TEXTURA EN EL GA$$anonymous$$EOBJECT
 
 function reemplazarImg(){
     
     renderer.material.mainTexture = texLocalPoner;
     yield;
 }
 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Making one directional virtual joystick OR smoothly transitioning between buttons 0 Answers

How to reduce scene load time on mobile? 2 Answers

Struggling with android adaptive icon. 1 Answer

Copy mp3 to cellphone 0 Answers

Does AssetBundle work on mobile? 0 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