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
Izabella S.
9 years agoNew member | Level 1
Java API Concurrency with multiple users accessing app.
So I am developing a Spellchecker application. I am storing all the projects (books) on Dropbox. My application downloads and uploads files to Dropbox.
The application will have multiple users who may possibly be accessing the same project at the same time. If two users finish processing the project at the same time (i.e. application starts to upload the same file at the same time to dropbox), I assume, one overwrites the other.
This would cause a problem for me. I would like to program the application to acquire a lease on a certain project, giving the user exclusive access to it. The point is at this link https://www.dropbox.com/developers/reference/webhooks I saw something about leases.
How do I implement a lease? In java in this dropbox API how to I assign exclusive access to a Dropbox folder for one user at a time?
Cheers
- Greg-DBDropbox Staff
Thanks for clarifying. The API was designed with the intention that each user would link their own Dropbox account, in order to interact with their own files. However, it is technically possible to connect to just one account. The SDKs don't offer explicit support for it and we don't recommend doing so, for various technical and security reasons.
However if you did want to go this route, instead of kicking off the authorization flow, you would manually use an existing access token for your account and app. (Just be careful not to revoke it, e.g. via https://www.dropbox.com/account/security .)
In any case, the Dropbox API doesn't offer any sort of file locking, so there isn't a good way to manage this, but I'll be sure to pass this along as feedback. (The mention of leases in the webhooks documentation was in reference to hypothetical leasing you could build into your app's own code when handling changes, not about making calls to the Dropbox API.)
Anyway, for handling how files are uploaded, and how to prevent and manage conflicts, you should read about the different write modes available. E.g., if you're using the Java Core SDK:
https://dropbox.github.io/dropbox-sdk-java/api-docs/v1.8.x/com/dropbox/core/DbxWriteMode.html
- Greg-DBDropbox Staff
If you will only have your app connect to a single account, you need to only process the OAuth app authorization flow for that account once. From that point on, you would store and re-use that single access token.
For example, if you are using the Java Core SDK, that is the token stored as "accessToken" in the tutorial.
Then, whenever a user of your app needs Dropbox functionality, you would use a DbxClient made with that stored access token, e.g., using this constructor.
- Greg-DBDropbox Staff
Exactly what happens depends on what API calls they're making. E.g., if they both try to read a file at the time time, that should be fine. On the other hand, if they both try to upload new versions of a single file at the same time, that will cause a conflict. Be sure to read through the write mode documentation I linked to earlier to understand the different modes and behaviors.
- Greg-DBDropbox Staff
Hi Izabella, to clarify, are all of the users of your app going to be connecting to the same Dropbox account, or will they be linking their own accounts?
- Izabella S.New member | Level 1
There is only one central account, like a database where all data is stored. Every different user accesses this central "database".
- Izabella S.New member | Level 1
Alright, but for my purposes the entire point of storing these project son dropbox is to only have one central account where different users have access to the same projects (and especially same dictionary from which spellchecking happens).
"However if you did want to go this route, instead of kicking off the authorization flow, you would manually use an existing access token for your account and app." -- Could you please be a little more technical? What exactly does this mean for the program.
Note I am a little new to drobox developement, so it may be obvious.. But you are saying that I should use one access token (this is the one that finalise() was called on?) to connect to dropbox for every user? So that would mean that there is only ever one person accessing dropbox because there is only ever one access token generated?
Cheers
- Izabella S.New member | Level 1
Thanks, and what happens when two different people(on different computers) hypothetically try to access the same central Dropbox account at the same time, using the same access code?
- Izabella S.New member | Level 1
Alright, thanks a mill Greg.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,884 PostsLatest Activity: 5 hours agoIf 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!