ES2Web.UploadFile
Parameters
path | The path of the file we want to upload. |
Returns
IEnumerator | The IEnumerator for the coroutine. |
Description
Uploads an entire local file to the server. This method is useful for easily syncing save data with the cloud.
Note that to load data from the file, you will need to download the entire file first, and then use ES2Web.SaveToFile to save it as a local file, or use ES2Web’s Load methods to load tags from it.
C#
Upload and Download a local file to and from a server
1 2 3 4 5 6 7 8 9 10 11 |
// Create a local file. ES2.Save(123, "myFile.txt?tag=myInt"); ES2.Save(new float[]{1f,2f,3f}, "myFile.txt?tag=myFloatArray"); // Upload the entire local file to the server. ES2Web web = new ES2Web("https://site.com/ES2.php?webfilename=myFile.txt"); yield return StartCoroutine( web.UploadFile("myFile.txt") ); // Download the file and replace the local file with it. yield return StartCoroutine( web.Download() ); web.SaveToFile("myFile.txt"); |
JS
Upload and Download a local file to and from a server
1 2 3 4 5 6 7 8 9 10 11 |
// Create a local file. ES2.Save(123, "myFile.txt?tag=myInt"); ES2.Save(new float[]{1f,2f,3f}, "myFile.txt?tag=myFloatArray"); // Upload the entire local file to the server. var web = new ES2Web("https://site.com/ES2.php?webfilename=myFile.txt"); yield return StartCoroutine( web.UploadFile("myFile.txt") ); // Download the file and replace the local file with it. yield return StartCoroutine( web.Download() ); web.SaveToFile("myFile.txt"); |