Uploading files to DropBox using UnityWebRequest.

Hello, i need to store game data in DropBox. Now i have the coroutine to download .json file from using UnityWebRequest, and it works great. But i am having difficulty in writing a Post method to upload a file to DropBox. Hope you help me.

    private string downloadUrl = "https://www.dropbox.com/s/27e3nqvw6283l16/data.json?dl=1";
    private string text = "";

    private void Start()
    {
        StartCoroutine(Get(downloadUrl));
    }

    private IEnumerator Get(string url)
    {
        using (UnityWebRequest request = UnityWebRequest.Get(url))
        {
            yield return request.SendWebRequest();

            if (request.isNetworkError || request.isHttpError)
            {
                Debug.LogErrorFormat("Request error: {0}", request.error);
            }
            else
            {
                text = request.downloadHandler.text;
                Debug.LogFormat("Recieved: {0}", text);
            }
        }
    }

There is no easy quick answer to this because accessing a public shared resource is of course easy. However any actions within a certain account requires authentication which is at least 10 times more complex than doing a single web request. You can read all necessary things on the API documentation of Dropbox. Note that for such service providers there usually exist wrapper frameworks like this one. Though installing such a framework can also come with its own issues. It also doesn’t need to be compatible with Unity. You may find implementations for Unity in the assetstore. Though most are probably not free.

Keep in mind that in order to upload files to dropbox you need a dropbox account. You either have to use your own, or if its a game you may offer the user to connect their dropbox. Though be warned that when you want to ship a game / application that is connected to your own dropbox account, you would need to ship the authentication information with your application so it could be stolen / intercepted. Though we don’t know what you want to do, so this was just a warning / notice. You are responsible for the security of your account :slight_smile: