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