cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you interested in learning how media industry leaders use Dropbox Replay? Register for our webinar here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to sync my app folder in dropbox?

how to sync my app folder in dropbox?

VDlasov
Explorer | Level 4

Hi, 

 

I write mobile application for os android with dropbox sync.

 

Application can work offline. User can change data in app or in dropbox app/web client. After user made some changes. I need to make synchronization current device data and server data. In hard conflicts user decide what of two copys keep (one left, one right or keep both).

 

I saw dropbox api v1 have folder sync, but now it's deprecated.

 

I need some help with sync.

 

--
Best regards,
Denis Vlasov

5 Replies 5

Greg-DB
Dropbox Staff

It sounds like you're referring to the Sync SDK, based on the deprecated API v1.

 

We don't have an equivalent SDK for API v2, but I'll be sure to pass this along as a feature request. That being the case, you'll need to implement the logic for offline caching and conflict resolution in your app using the API v2 calls. 

 

Apologies I don't have an easier solution for you!

VDlasov
Explorer | Level 4
Thanks ,Greg! But I'm not looking for a simple solution.

Maybe you can recommend some books, articles, blogs, etc? In any language.
I want to implement robust and right solution.

--
Best regards,
Denis Vlasov

Greg-DB
Dropbox Staff
I'm afraid I can't recommend any particular third party resources unfortunately, Denis. Perhaps some other developers on the forum here can recommend some though.

Keith B.7
Helpful | Level 7

There's a decent example of using the Dropbox API to sync a folder between the local device and the server here:

 

https://github.com/chrishulbert/CHDropboxSync/blob/master/CHDropboxSync.m

 

It's written in Objective-C and uses the Core API (API 1), but the basic logic is good. You'd need to translate it to your language and API 2 (e.g. using listFolderContinue instead of getMetaData). The basic principle is:

 

1. Use listFolder (recursive) to get a list of all files inside the specified folder on Dropbox.

 

2. Compare this against the list of files in the local folder (e.g. by date).

 

3. Download and upload as necessary.

 

4. At the end of the sync, save a cached list of all files in the local folder and their modified dates, along with the current delta cursor.

 

5. For the next sync, use -listFolderContinue: with the cached delta cursor to get a list of changes on Dropbox since the last sync. Combine these changes with your cached list of files and folders to get the current state of all files and folders on Dropbox (this is quicker than just running listFolder every time).

 

6. Get a list of local files in the local folder, including dates. So you now have three lists of the files: (1) a list of the files and mod dates from the cached list as they were at the end of the last sync; (2) a list of the files as they exist on the Dropbox servers; (3) a list of files as they exist locally.

 

7. You can now go through these lists to build a list of sync tasks. E.g. If a file exists locally but not in the cached list or on the server, then it's been created locally since the last sync, so you need to upload it; if a file exists on the servers but not locally or in the cached list, then it has been added to Dropbox so you need to download it; if a file exists in the cached list and in the server list but not locally, then it's been deleted locally, so delete it from Dropbox. If a file has the same date on Dropbox and in the cached list but a newer date locally, then it's been changed locally and you need to update it. If a file has newer dates both on Dropbox and locally than in the cached list, then it's been edited in two places so you have a conflict and need to deal with it.

 

For this to work properly, it's crucial that the dates of files on the server and locally are kept in sync, but fortunately API 2 lets you set the server date, so this isn't too hard.

 

I used the basic logic in CHDropboxSync as a jumping off point for my own iOS implementation, which is now in a shipping app and working well.

 

Hope that's of some help.

 

All the best,
Keith

 

 

Gato-Gato
Explorer | Level 4

@Keith B.7 Super helpful, thank you from 2021 where there's still no better solution.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Gato-Gato Explorer | Level 4
  • User avatar
    Keith B.7 Helpful | Level 7
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    VDlasov Explorer | Level 4
What do Dropbox user levels mean?