Search code examples
iosdropboxdropbox-api

iOS dropbox SDK loading thumbnails and number of files inside a folder


Hi all I am developing an application that brings up the entire folder and file structure from any content management system for now I have done Box and sharepoint integration. I am looking to sync dropbox now. In the DBMetaData class I have properties

BOOL thumbnailExists;
NSArray* contents;
NSString* icon;
  1. First thing I want to do here is that I want to load thumbnails of files, I do not get one thing the icon property returns a string, like this 'page_white_acrobat' (I thought it would return a url or something where I could download the thubmnail). Is there any way to bring thumbnails using the dropbox sdk. Also I uploaded a .mp4 file and .png file, they show up thumbnails when I open dropbox in chrome but in the SDK the thumbnailExists property returns NO.

  2. Second I want the number of sub folders and the files for a folder, I tried accessing the contents property of a folder DBMetaData Object and it returned nil. Is there any way in the SDK to count the number of files inside a folder or any work around.


Solution

    1. It seems that Dropbox just provides the name of the icon they use. You can't download it, so you should check this string and use resources in your app bundle.

    2. The contents of a DBMetadata object will be null until you actually make a request to load metadata at that path.

    This code will get you started with subdirectories.

    -(void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata
    {
        // LOAD METADATA OF SUBDIRECTORIES
        for (DBMetadata *node in metadata.contents) {
            if (node.isDirectory) {
                [_restClient loadMetadata: node.path];
            }
        }
    
        // GET COUNT OF DIRECTORY CONTENTS
        if (metadata.isDirectory) {
            NSLog(@"%@ contains %d files and folders", metadata.path, metadata.contents.count);
        }
    }