0
votes

I'm using the Dropbox Sync API in a Android app to put Photo's on Dropbox. The photos are stored in a DbxFile. Immediately after the creation of the files, I can re-open them without any problem, but once the files are uploaded, I can't open about half of the files on the mobile device. (On my PC, they are ok.) With the files that are no longer accessible, the Sync api seems to know there is a newer version, but for some reason they are not updated.

public Bitmap getBitmapFromFile(String path) throws Exception {
    DbxFile dbxFile = dbxFileSystem.open(new DbxPath(path));

    DbxFileStatus newerStatus = dbxFile.getNewerStatus();

    if (newerStatus != null && newerStatus.isCached) {
    // this is +/- one-half of the time the case. Appears to be random?
        dbxFile.update(); //This is executed, but no update??
    }

    Bitmap bitMap = BitmapFactory.decodeStream(dbxFile.getReadStream());
    dbxFile.close();
    return bitMap;
}

When I try to open a file that is no longer accessible, this line appears in LogCat:

libDropboxSync.so(open) file.cpp:329: opening at  (da618e76aab is latest)

By opening a file without problems, this line appears:

libDropboxSync.so(open) file.cpp:336: opening at da418e76aab (latest)

Why is the update not executed? Any help is highly appreciated, thanks.

1

1 Answers

0
votes

The Sync API only starts to download new content for files when you open them. For the new version of the file to get downloaded, you need to open the file and hold it open (and register a listener so you know when the download has completed).

In your code, you're opening the file and then almost immediately closing it again. This means you will almost never get new versions of files and will just read the same cached version forever.

Except in very rare timing conditions, I would expect your condition newerStatus.isCached to never be true, since you just opened the file a line earlier. (Opening the file should give you the latest cached version, so there shouldn't be a newer version that's already cached... otherwise you would have gotten it already.)