mmagician
mmagician

Reputation: 2120

Efficient syncing of app data to the App folder in Google Drive

I'm developing an app which stores items for the user, and the user has an option to sync with Google Drive. Each item consists of text and image.

My current method is to save a .json and .jpg file for each item internally to the device, and then once onConnected is called from Drive APIs, upload these files to the user's APP folder in Google Drive. Similar with deletion, I would create a flag that an item with name 'foo' has been deleted, then try to see if the files 'foo.jpg' and 'foo.json' exists in Drive, and delete accordingly.

This works for me now, but often I get the app to crash because of googleApiClient errors and I realize that this is not an efficient method. So what I'm wondering is whether any of you guys know a more efficient method to do this?

In the ideal world I would love to have something like this: I save the files for each item to the device internally, and a library tracks these and sync Drive accordingly.

Thanks for advice!

Upvotes: 2

Views: 795

Answers (1)

seanpj
seanpj

Reputation: 6755

Based on the fact that you are referring to 'onConnected' and 'googleApiClient', I assume that you're using GDAA not the REST Api.

You should re-think the idea of using file names when dealing with GooDrive. They are not unique in GooDrive and the GDAA's latency will sooner or later cause a problem with presence of multiple files with the same name, created by ubiquitous construct:

  if file.name not exist
    create file.name

The fact that you use APP folder makes debugging even harder since you don't have feedback by looking at the http://drive.google.com.

You should refer to your files by the DriveId (if using only a single Android device) or by the ResourceId (if you intent to send/broadcast the IDs to a different device/app). And if you decide to use the ResourceId, make sure you handle the latency issues caused by delayed GDAA's promotion of objects to the Drive.

This certainly does not fully cover your question, but it is too broad to answer correctly anyway.

Good Luck

Upvotes: 1

Related Questions