(Solved - issue was on my server side) Issues with the upload/download code example
Posted: Tue Sep 08, 2020 2:38 pm
Hey Joel,
I was using the code example found at https://moodkie.com/forum/viewtopic.php?f=16&t=1707 but i cant seem to get it to work. heres exactly what my code looks like except for the server data which i removed:
it all seems to work until it gives me the error "uploaded file does not exist or is empty". before it gives me the "(writing property)" logs id expect and a "Committing backup for SaveFile.es3 to storage location InternalMS" before the error.
Thanks!
I was using the code example found at https://moodkie.com/forum/viewtopic.php?f=16&t=1707 but i cant seem to get it to work. heres exactly what my code looks like except for the server data which i removed:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DBConnect : MonoBehaviour
{
// Your ES3Cloud.php details
public string url = "";
public string apiKey = "";
// The variables you want to upload/download.
int myInt = 123;
Vector3 myVector3 = new Vector3(1f, 2f, 3f);
// Call these to upload or download.
public void Upload() { StartCoroutine(UploadRoutine()); }
public void Download() { StartCoroutine(DownloadRoutine()); }
// Start is called before the first frame update
void Start()
{
StartCoroutine(UploadRoutine());
}
// Update is called once per frame
void Update()
{
}
private IEnumerator UploadRoutine()
{
// Create a new ES3File, and ensure we specify false as the parameter
// so that we don't sync it to local storage
Debug.Log("Uploading...");
var file = new ES3File(false);
// Save data to our ES3File in memory.
file.Save<int>("myInt", myInt);
file.Save<Vector3>("myVector3", myVector3);
// Create an ES3Cloud and upload the file.
var cloud = new ES3Cloud(url, apiKey);
yield return cloud.UploadFile(file);
// If an error occurs, log it to console.
if (cloud.isError)
Debug.LogError(cloud.error);
else
Debug.Log("Uploaded");
}
private IEnumerator DownloadRoutine()
{
// Create a new ES3File, and ensure we specify false as the parameter
// so that we don't sync it to local storage
var file = new ES3File(false);
// Create an ES3Cloud and download the file.
var cloud = new ES3Cloud(url, apiKey);
yield return cloud.DownloadFile(file);
if (cloud.isError)
Debug.LogError(cloud.error);
else
Debug.Log("Downloaded");
// Load the data from the ES3File and back into our variables.
// We set the defaultValue parameter incase data doesn't exist.
myInt = file.Load<int>("myInt", 0);
myVector3 = file.Load<Vector3>("myVector3", Vector3.zero);
}
Thanks!