Download pictures from server to local

Source: Internet
Author: User

Download img resources from the server
Private IEnumerator downloadtolocalimg (string url, string strname)
{

Debug.Log ("Download resource from server img:" + strname);
URL encoding
WWW.EscapeURL (URL);
Access URL
www www = new www (URL);
URL decoding
WWW.UnEscapeURL (URL);
Gets the name of the file based on the URL.
string filename = URL. Substring (URL. LastIndexOf ('/') + 1);
Debug.Log ("filename++++++++++++++++++++++" + filename);
Wait for download
yield return www;

Instantiate (Www.assetBundle.mainAsset);

if (Www.error = = null)
{
Debug.Log (WWW);
Path is where you want to save the file.
FileStream fs = file.create (Application.persistentdatapath + "/" + filename);
Downpath = Application.persistentdatapath + "/" + filename;
Write the downloaded data to a file
Fs. Write (www.bytes, 0, www.bytes.Length);
Fs. Close ();

Debug.Log (filename + "Download complete");

Loading img
Rawimage.getcomponent<rawimage> (). Texture = loadimg (strname + ". jpg");

}
Else
{
Debug.Log (Www.error);
}
}

Download pictures from server to local

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.