Threading and Dropbox

927 Views Asked by At

I'm developing an application that might use Dropbox as it's storage.

My question is, you can link folders between computers, so that more than 1 person could upload/download to/from the same folder.

Do I have to worry about threading? What happens if while a person is downloading a file, the other person is updating the same file. Does dropbox lock the file while one operation is being done on it? If not, I guess I have to handle it in my application correct?

2

There are 2 best solutions below

3
On BEST ANSWER

Yes, you do have to worry about this.

Dropbox uses optimistic concurrency. Every file has a rev (revision) that you can reference when uploading a file (e.g. via /files_put). So the basic idea is that when you download a file, you keep track of the rev, and when you upload the file, you pass that rev as the parent_rev parameter. If the file has been changed in the meantime by a different user (via a shared folder) or the same user (via a different device), the rev won't match. What happens then is dictated by the autorename parameter. If you specify true, the file will get renamed on conflict. If you specify false, the upload will fail altogether, and your app can decide what to do.

Essentially, you can't stop users from updating files simultaneously on multiple devices, but you can (and should) deal with these conflicts in your app, and the rev is what lets you ensure no data is lost.

2
On

When a conflict happens dropbox will make a copy of the file and the file name contains the date and host name (for example, for MarkoLaptop as hostname and 21st of January 2015 for conflict date will generate a file called README.TXT (MarkoLaptop's conflicted copy 2015-01-21)), so if you can handle it in the app, that's great <3