Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

jacqkl's avatar
jacqkl
Explorer | Level 3
7 years ago
Solved

Issues with long term polling for file changes

My (Java) app. needs to know how a Dropbox filesystem (or part of it) changes and also has changed while she's not running. The listFolderLongpoll API seems to be well suited for this purpose and my...
  • Greg-DB's avatar
    7 years ago

    My (Java) app. needs to know how a Dropbox filesystem (or part of it) changes and also has changed while she's not running.

    The listFolderLongpoll API seems to be well suited for this purpose and my first tests are promissing.


    You can use the listFolder[*] methods to see what exists in the account, and what has changed. The listFolderLongpoll method in particular is only meant for when apps are running, not for when they're not running. It allows the app to hold open a long running connection to receive low latency notification of when changes occur, which doesn't work if the app isn't running.

    The basic flow should work like this:

    • The app uses listFolder to begin listing items, and saves the returned cursor.
    • If 'has_more' was returned as true, the app uses the resulting cursor with listFolderContinue to continue listing more items, and saves the latest returned cursor, and repeats if 'has_more' is still true.
    • Once caught up (i.e., 'has_more' is false), the app can use the latest cursor with listFolderLongpoll to monitor for changes.
    • If any changes occur, the apps calls listFolderContinue again to get the changes, and repeats.
    • The app is quit by the user at any point.
    • The app is re-launched by the user at any point.
    • The app uses the latest cursor with listFolderContinue again to get any changes that occurred when it wasn't running, and repeats the process.

    First question:  how long will a cursor be valid ?, for a few hours? , days ?, more ?


    Cursors don't expire automatically, however there are some scenarios where they can become invalid. You should catch ListFolderContinueErrorException when calling listFolderContinue accordingly. A ListFolderContinueError.RESET indicates that the cursor is no longer valid.


    But there is one problem, with file renaming; it's seen by the app. as the pair (deleted, new) and, unless my test code is buggy, I don't see any way to "reconstruct" the rename infos. , especially in case of several renames (I didn't test yet the "move" which also must work..).


    Yes, renames (and moves) are reported as a deletion/addition pair. You can track files across renames and moves using the file ID, which doesn't change for renames/moves.


    Second question: what are the alternative to long term poll? , knowing that solutions based on "webhooks like" techniques are not an option.


    In general, longpolling is meant for client-side apps, and webhooks are meant for server-side apps. If neither work for your use case, the alternative is to just call listFolderContinue ocassionally to check for changes.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!