cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Java API Concurrency with multiple users accessing app.

New member | Level 1
New member | Level 1

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

8 Replies 8
Highlighted

Re: Java API Concurrency with multiple users accessing app.

Dropboxer
Dropboxer

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?

Highlighted

Re: Java API Concurrency with multiple users accessing app.

New member | Level 1
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".

Highlighted

Re: Java API Concurrency with multiple users accessing app.

Dropboxer
Dropboxer

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

Highlighted

Re: Java API Concurrency with multiple users accessing app.

New member | Level 1
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

 

Highlighted

Re: Java API Concurrency with multiple users accessing app.

Dropboxer
Dropboxer

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.

Highlighted

Re: Java API Concurrency with multiple users accessing app.

New member | Level 1
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?

Highlighted

Re: Java API Concurrency with multiple users accessing app.

Dropboxer
Dropboxer

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.

Highlighted

Re: Java API Concurrency with multiple users accessing app.

New member | Level 1
New member | Level 1

Alright, thanks a mill Greg.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?