cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Error downloading multiple files from dropbox to the phone via the Sync API

Error downloading multiple files from dropbox to the phone via the Sync API

Mob A.
New member | Level 1

Hi,

I am trying to sync a specific folder from dropbox to the mobile using the Sync API in my Android app. I use the listFolder method to get the contents of the folder and then iterate over the dbxPaths to download each of them. This works but sometimes I get the following fatal error:

02-05 10:45:30.014: E/libDropboxSync.so(err)(12094): ASSERTION FAILED: 'path->m_refcount' is false, should have been true

Any idea why this is happening? ANy help will be appreciated.

7 Replies 7

Greg-DB
Dropbox Staff

Thanks for the report. First, can you confirm that you're using the latest version of the Android Sync SDK, currently v3.1.2?

Also, is this related to your other question or should we consider this a separate issue?

In any case, if you can supply the relevant code snippet(s) that should be helpful.

Mob A.
New member | Level 1

Hi Greg,

Here's the code snippet:

Type type = new TypeToken<List<DbxFileInfo>>(){}.getType();
List<DbxFileInfo> dbxFileInfoList = gson.fromJson(restoredData, type);

DbxPath path = null;

DbxFileInfo fileInfo = null;
File restoredFile = null;
int numOfFiles = dbxFileInfoList.size();
FileChannel src = null;
FileChannel dst = null;

try {
    DbxFileSystem dbxFs = DbxFileSystem.forAccount(MyApplication.mDbxAcctMgr.getLinkedAccount());

    for(int i = 0; i < numOfFiles; i++)
    {
        //fileInfo = dbxFileInfoList.get(i);
        DbxFile testFile = null;
        path = dbxFileInfoList.get(i).path;

        if(!dbxFs.isFile(path))
        {
            break;
        }

        testFile = dbxFs.open(path);
        restoredFile = new File(Constants.APP_DIR,path.getParent() + "/" +  path.getName());

        if(!restoredFile.exists())
        {
            src = testFile.getReadStream().getChannel();
            dst = new FileOutputStream(restoredFile).getChannel();
            dst.transferFrom(src, 0, src.size());
            createSessionWithAudio(restoredFile.getAbsolutePath(), dbxFileInfoList.get(i).modifiedTime, dbxFileInfoList.get(i).size);
        }
        src.close();
        testFile.close();
        dst.close();
        restoreCount++;
    }

    dbxFs.shutDown();

} catch (Unauthorized e) {
    Log.e(TAG, "Unathorized Dropbox access");
} catch (InvalidPathException e) {
    Log.e(TAG, "Invalid Dropbox file path");
} catch (DbxException e) {
    Log.e(TAG, "Dropbox exception");
} catch (IOException e) {
    Log.e(TAG, "IO exception during dropbox sync");
}
catch(Exception e)
{
    Log.e(TAG, "Exception during dropbox sync");
}

The code being run for the other question is the same. However, the issues are separate.

Mob A.
New member | Level 1

Also, yes I am using the latest Android Sync SDK v3.1.2.

Greg-DB
Dropbox Staff

Thanks for the code! Based on gson.fromJson(restoredData, type);, it looks like you're using some sort of sort of serialization framework to store and retrieve DbxFileInfo to/from JSON, is that correct? We don't explicitly support that, and it's possible that this is causing the issue. Can you try it without that part?

Also, can you elaborate a bit on why you're trying to store and retrieve this information like this anyway? The SDK caches metadata for you, so you can even access it offline.

Mob A.
New member | Level 1

Hi Greg,

Essentially, I want to allow the user an option to retrieve backed up files from a specific folder from Dropbox when he reinstalls my app or installs it on another device. I serialize the list of available files since I do not want to run the 'listFolder' query repeatedly. I doubt there is an issue with the serialization since the same code works 2 out of 3 times.

I tried running the code without the deserialization part with the same result. The code crashes in libDropboxSync.so once in 3 times (on an average).

I am new to the Sync API. Is there a better way of providing the functionality I mentioned in the first paragraph by using the Sync API itself? I believe the API does not have a method to download all files from a specific folder.

Greg-DB
Dropbox Staff

The metadata is cached, so there's no harm in calling listFolder as much as needed. We definitely don't recommend serializing/deserializing the objects though, as there is some special initialization that occurs, which you won't get when deserializing and could cause problems.

Anyway, you're correct that there's currently no way to download an entire folder at once besides looping through all the desired files and opening them. The Sync SDK wasn't designed with a convenient way to do so since it was meant for mobile devices and the intent was that data would only be downloaded if/when necessary (e.g., when the user wants to interact a particular file's content).

Can you post your new code without the serializing/deserializing so we can continue investigating? (It may be worth uninstalling/reinstalling the app in case you have some corrupt state due to that.)

Mob A.
New member | Level 1

Greg,

My apologies for the delayed response.

The code works reliably if the serialization is removed. Thanks for the help.

Regards,
Neeraj

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Mob A. New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?