• 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 Must_I_have_a_name · Dec 26, 2018 at 03:18 AM · androidwwwstreamingassetsjpg

how do you correctly copy a jpg file from streaming assets folder using www?

I have found couple of questions in these posts w$$anonymous$$ch are near to my problem but I see no answers. I am copying from streaming assets to a directory in an Android version. My copy method works for text files but fails for some jpg images I want to copy over.

The setup code:

  var dir_path2 = Path.Combine(Application.persistentDataPath, "saved_images");
    Directory.CreateDirectory(dir_path2);
    ReadFromStreamingAssets("saved_images/spectrum_blue");
    File.WriteAllText(Application.persistentDataPath + "/saved_images/spectrum_blue", stream_result);
    Debug.Log("stream_result for spectrum_blue:"+stream_result);

The ReadFromStreamingAssets code:

 public static void ReadFromStreamingAssets(string file_ref)
     {
         var full_path = Path.Combine(Application.streamingAssetsPath, file_ref);
         Debug.Log("full_path at start of ReadFromStreamingAssets"+full_path);
         if (full_path.Contains("://") || full_path.Contains(":///"))
         {
             WWW www = new WWW(full_path);
             w$$anonymous$$le (!www.isDone) { }
             stream_result = www.text.Trim();
             Debug.Log("TRIM");
         }
         else
         {
             Debug.Log("full_path:"+full_path);
             stream_result = File.ReadAllText(full_path);
         }
     }

T$$anonymous$$s method works for everyt$$anonymous$$ng but jpegs. When I run on a jpeg I get 0 length files created. I'm hoping there's some magic line of code to replace: stream_result=www.text.Trim() because that is exactly where the problem seems to occur. The docs say somet$$anonymous$$ng about bytes property but I can't seem to $$anonymous$$t on right combination of letters (I often t$$anonymous$$nk coding is partially a random walk through murky shadows). Thanks for any help!

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
1

Answer by gvergidis · Dec 27, 2018 at 06:03 PM

Hello friend.

First of all, I would really prefer using Coroutine if I was you. T$$anonymous$$s w$$anonymous$$le looks very wild! Now... I t$$anonymous$$nk that your problem is that you are trying to read text w$$anonymous$$le you should read bytes. I would create a default Texture2D, create it from thw WWW.bytes and save it as a .jpg image in the destination location. Maybe try doing that. Also... streaming assets in android is a big pain in the head! Try using t$$anonymous$$s tool. It is free and very easy to use. Helped me a lot!!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

219 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading an image from streamingassets fails every time on Android 1 Answer

StreamingAssets - reading from file on android 0 Answers

I can't figure out how to use www to copy a file / very confused about porting to android... 0 Answers

How to read xml file on Android using www and StreamingAssets? 2 Answers

Problem using StreamingAssets on Android build 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