1
\$\begingroup\$

I have made text file and I put it on Dropbox, I have in this text file a value. From my code, I want to check if this value is 1.

I have tried this code, inspired by the Unity example, but it looks like I'm not able to reach the file.

void Start()
{
    StartCoroutine(GetText());
}

IEnumerator GetText()
{

    UnityWebRequest www = UnityWebRequest.Get("https://www.dropbox.com/s/6jkhtnpskzsi5pj/TestTXT.txt?dl=0");
    yield return www.SendWebRequest();

    if (www.isNetworkError || www.isHttpError)
    {
        Debug.Log(www.error);
    }
    else
    {
        // Show results as text
        Debug.Log(www.downloadHandler.text);
        // Or retrieve results as binary data
        byte[] results = www.downloadHandler.data;
    }
}
\$\endgroup\$
0

2 Answers 2

1
\$\begingroup\$

It looks like Unity was not able to download the file. To fix this, I set the dl=1 in the Dropbox URL, instead of dl=0.

Here is the code that made it work for me:

public class DMROnline : MonoBehaviour
{
    public string Active;
    public string Disable;

    public TextAsset textFile;
    void Start()
    {
        StartCoroutine(GetText());
    }

    IEnumerator GetText()
    {
        UnityWebRequest www = UnityWebRequest.Get("https://ucc4b7b1ad9c37a497d7fda64ed6.dl.dropboxusercontent.com/cd/0/get/AoPqwsZg_TSmt1UXQMastDHIcrmf3T5GMlbzHmcj4P0ppWKsKA1qWlRtDM5p-6wCBKMxbuacBGzYaLzUwSg30UekYJ4ntqa0-Oxrg6mG6BImz7wfRzon9OAz2IBTTd1VF5g/file?dl=1#");
        yield return www.SendWebRequest();

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {
            // Show results as text
            Debug.Log(www.downloadHandler.text);
            // Or retrieve results as binary data
            byte[] results = www.downloadHandler.data;

            string pathTxt = www.downloadHandler.text;
            Console.WriteLine(pathTxt);
            Debug.Log(pathTxt);
        }
    }
}

I also had to make sure that the folder holding the file is public, not private.

\$\endgroup\$
1
  • \$\begingroup\$ UnityWebRequest.Get(url) is the thing which solved it for me instead of using new UnityWebRequest(url) \$\endgroup\$ Jun 17, 2021 at 23:20
0
\$\begingroup\$

i think dropBox is all about downloading. you have no access to serverside logic so for reading a file you have to download it

im not sure about dropBox but requesting from A server of cloud from an app is different from browsers as you dont have sessions and cookies for app requests. certainly you need some authentication headers. try to send a request. if you receive 4XX specially 403 it means you need authentication.

\$\endgroup\$
3
  • \$\begingroup\$ Is there a better cloud ؟ \$\endgroup\$ Sep 9, 2019 at 17:14
  • \$\begingroup\$ @NADERLABBAD if you want to read a file in server side you have to have a serverside login to open the file at serverside and send you its contents. i dont know there is a server or cloud that can give you this. \$\endgroup\$
    – virtouso
    Sep 9, 2019 at 17:17
  • \$\begingroup\$ In fact I have succeeded it is A private folder must be public \$\endgroup\$ Sep 9, 2019 at 17:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .