You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

nickthehero's avatar
nickthehero
Explorer | Level 3
7 years ago

Java API - What is the best way to get a user's remaining free space using DbxClientV2?

subject is self-explanatory. I can't seem to find any good info on the matter. I'm not sure exactly how storage values work in V2, as the docs are a bit... ambiguous. Or else i just cant find the right info. Best way to get this info? Thanks in advance :D

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    To get the user's space usage via the API v2 Java SDK, you should use DbxUserUsersRequests.getSpaceUsage. That will return a SpaceUsage object, which contains information about their 'allocation' (their total quota) and their 'used' (the amount of space they're currently using. To get the "free" amount, subtract the 'used' from the 'allocation'.

     

    Note that their 'allocation' will be a SpaceAllocation object with more detail information so you can distinguish between shared team quota (if they're on a team, since team accounts share their quota) or individual quota.

     

    If you're having trouble writing code to get the specific value you want, please share the code you have so far and let us know what you're stuck on.

    • nickthehero's avatar
      nickthehero
      Explorer | Level 3

      Greg-DB wrote:

      To get the user's space usage via the API v2 Java SDK, you should use DbxUserUsersRequests.getSpaceUsage. That will return a SpaceUsage object, which contains information about their 'allocation' (their total quota) and their 'used' (the amount of space they're currently using. To get the "free" amount, subtract the 'used' from the 'allocation'.

       

      Note that their 'allocation' will be a SpaceAllocation object with more detail information so you can distinguish between shared team quota (if they're on a team, since team accounts share their quota) or individual quota.

       

      If you're having trouble writing code to get the specific value you want, please share the code you have so far and let us know what you're stuck on.


       

      It's not clear what their total allocation of their dropbox is then, so this answer only help me partially.

       

      Does their whole personal dropbox size = .getSpaceUsage.getAllocation.getIndividualValue.getAllocated ?

      • Greg-DB's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox Staff

        Yes, that would make sense for a personal, not Business, account. Here's a basic example that checks the type to handle either:

         

        SpaceUsage spaceUsage = client.users().getSpaceUsage();
        
        long allocated;
        if (spaceUsage.getAllocation().isTeam()) {
            System.out.println("Team allocation:");
            allocated = spaceUsage.getAllocation().getTeamValue().getAllocated();
        } else {
            System.out.println("Individual allocation:");
            allocated = spaceUsage.getAllocation().getIndividualValue().getAllocated();
        }
        
        System.out.println("Total: " + allocated);
        long used = spaceUsage.getUsed();
        System.out.println("Used: " + used);
        System.out.println("Free: " + (allocated - used));
        

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,902 PostsLatest Activity: 19 hours ago
332 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!