We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

sisrael1's avatar
sisrael1
New member | Level 2
2 years ago

Downloading and uploading files from dropbox .net sdk using my own account

Hi im new to developing with dropbox and im having a hard finding the following info. im using dropbox .net sdk to upload and download images from my own account i set up a little test using the generated access token from developer app portal, this token is short lived (starts with sl.) i've seen based on some question that dropbox no longer offers long lived tokens, so how can i implement a refresh token process without any interaction? 

 

heres the test code for refrence

 

 

try
        {
            var filePath = "PATH";
            var dbx = new DropboxClient("sl.TOKEN_HERE"); // Replace with your actual access token

            var response = dbx.Files.DownloadAsync(filePath).Result;

            if (response.Response.IsFile)
            {
                var fileContent = response.GetContentAsByteArrayAsync().Result;
               
                string base64String = Convert.ToBase64String(fileContent);
                return Ok(base64String);
            }
            else
            {
                // Handle the case where the response is not a file (e.g., it's a folder).
                return BadRequest("Requested item is not a file.");
            }
        }
        catch (Exception e)
        {
            throw new InternalServerException(e.Message);
        }

 

 


  • sisrael1 wrote:

    ..., so how can i implement a refresh token process without any interaction? 

    ...


    Hi sisrael1,

    Without any interaction - impossible. Unfortunately, Dropbox doesn't provide a way to receive refresh token as it was for long lived access token (not yet at least). You need to perform one interaction, at least, either within the application or by hands - some initial (interactive) steps. You may take a look here of how you can get refresh token (there entire process is shown; you don't need the last steps, since they are implemented in SDK) and after that just initialize your Dropbox client object with that tokens and keys (not just access token only like you are doing right now).

    Hope this helps.

  • Здравко's avatar
    Здравко
    Legendary | Level 20

    sisrael1 wrote:

    ..., so how can i implement a refresh token process without any interaction? 

    ...


    Hi sisrael1,

    Without any interaction - impossible. Unfortunately, Dropbox doesn't provide a way to receive refresh token as it was for long lived access token (not yet at least). You need to perform one interaction, at least, either within the application or by hands - some initial (interactive) steps. You may take a look here of how you can get refresh token (there entire process is shown; you don't need the last steps, since they are implemented in SDK) and after that just initialize your Dropbox client object with that tokens and keys (not just access token only like you are doing right now).

    Hope this helps.

    • sisrael1's avatar
      sisrael1
      New member | Level 2

      Thank you for you're response i have read that post before asking my question, the difficulty im having is the following, im only using my own user account in dropbox to store images and its being done by my backend (c# web api) so this auth flow as described in that post needs to happen when and where exactly? i hope you understand my difficulty here from this poorly written reply

      • Здравко's avatar
        Здравко
        Legendary | Level 20

        Hi again sisrael1,

        Yes, I understood what you mean. 🙂

         


        sisrael1 wrote:

        ... so this auth flow as described in that post needs to happen when and where exactly? ...


        At any moment before you're going to use your system (let's say right now would be fine). That flow needs to be performed a single time only and, as mentioned there, refresh token doesn't expire. So,... your system will be ready for use for... ever. 😉 (or till revoke)

        Hope this clarifies matter.

         

        PS: I forgot to mention that you can execute the commands wherever convenient for you (let's say on the machine you are posting now would be fine).

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 8 hours ago
325 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!