简体   繁体   中英

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.

  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);
    }
}

To list the contents of a path or directory, you need to call the following method of your DBRestClient object:

 - (void)loadMetadata:(NSString*)path;

which then invokes the following delegate callback(please see the method body for code to download the thumbnail for each file in the listed directory):

 - (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
 {
     for (DBMetadata *file in metadata.contents)
     {
         // 1. Use the DBMetadata * file object to do things like: add a table-view cell for the file.
         [self.filesListView addCellForFile: file];
         // 2. Request thumbnail for each file
         NSString *localThumbnailPath = [self localThumbnailPathForFile: file]; // create a local-file-path for the thumbnail
         [dbRestClient loadThumbnail: file.path ofSize:@"l" intoPath:localThumbnailPath];
     }
 }

In the method above, the loadThumbnail:ofSize:intoPath: method will result in invoking the following delegate callback:

 - (void)restClient:(DBRestClient*)client loadedThumbnail:(NSString*)localPath

from which, you must use the given localPath to update your UI with the downloaded thumbnail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM