使用 getThumbnailBatch 获取 Dropbox 缩略图

Posted

技术标签:

【中文标题】使用 getThumbnailBatch 获取 Dropbox 缩略图【英文标题】:get dropbox thumbnails with getThumbnailBatch 【发布时间】:2020-05-13 04:01:56 【问题描述】:

我正在使用 Dropbox objc API,我正在尝试获取特定 Dropbox 文件夹中的所有缩略图。

但我完全卡在 DBFILESGetThumbnailBatchArg 上。如何启动文件夹中所有图像的路径?

这是我坚持的路线:

    [[client.filesRoutes getThumbnailBatch:<#(nonnull NSArray<DBFILESThumbnailArg *> *)#>] 
setResponseBlock:^(
DBFILESGetThumbnailBatchResult * _Nullable result, 
DBFILESGetThumbnailBatchError * _Nullable routeError, 
DBRequestError * _Nullable networkError)  etc etc..

文档说

DBFILESThumbnailArg *arg = [[DBFILESThumbnailArg alloc] initWithPath:<#(nonnull NSString *)#>];


DBFILESGetThumbnailBatchArg *batchArg = [[DBFILESGetThumbnailBatchArg alloc] 
initWithEntries:<#(nonnull NSArray<DBFILESThumbnailArg *> *)#>];

如何初始化 DBFILESThumbnailArg 的路径列表?

文档链接: https://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/Classes/DBFILESRouteObjects.html#/c:objc(cs)DBFILESRouteObjects(cm)DBFILESGetThumbnailBatch

【问题讨论】:

【参考方案1】:

如您所见,the getThumbnailBatch method 需要 NSArray&lt;DBFILESThumbnailArg *&gt;,因此调用它看起来像这样:

NSArray<DBFILESThumbnailArg *> *entries = @[[[DBFILESThumbnailArg alloc] initWithPath:@"/test1.jpg"], [[DBFILESThumbnailArg alloc] initWithPath:@"/test2.jpg"]];
[[client.filesRoutes getThumbnailBatch:entries]
 setResponseBlock:^(DBFILESGetThumbnailBatchResult *result, DBFILESGetThumbnailBatchError *routeError, DBRequestError *networkError) 
    if (result) 
        NSLog(@"result:");
        NSLog(@"%@", result);
     else if (routeError) 
        NSLog(@"routeError:");
        NSLog(@"%@", routeError);
     else if (networkError) 
        NSLog(@"networkError:");
        NSLog(@"%@", networkError);
    ;
];

【讨论】:

是的,但是当上传或删除新的图像时,图像的数量会发生变化,我需要一个更动态的代码。 NSArray *entries,应该是 NSArray *entries【参考方案2】:

我使用 NSMutableArray 解决了这个问题,如果其他人来找我,请发布我的解决方案:

    //Create a temporary NSMutableArray
    NSMutableArray *thumbArgMutable = [[NSMutableArray alloc] init];

        for (NSString* image in _images)
        
            //Create DBFILESThumbnailArg from NSString
            DBFILESThumbnailArg *arg = [[DBFILESThumbnailArg alloc] initWithPath:image];

            //Add path as DBFILESThumbnailArg to NSMutableArray
            [thumbArgMutable addObject:arg];
        

        //Copy NSMutableArray to a new DBFILESThumbnailArg
        DBFILESThumbnailArg *thumbArg = [thumbArgMutable copy];

        //create a DBFILESGetThumbnailBatchArg and init with the copied DBFILESThumbnailArg
        DBFILESGetThumbnailBatchArg *thumbArgBatch = [[DBFILESGetThumbnailBatchArg alloc] initWithEntries:thumbArg];

        DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:@"TOKEN"];

        //use property entries from DBFILESGetThumbnailBatchArg
        [[client.filesRoutes getThumbnailBatch:thumbArgBatch.entries]
         setResponseBlock:^(DBFILESGetThumbnailBatchResult * _Nullable result,
                            DBFILESGetThumbnailBatchError * _Nullable routeError,
                            DBRequestError * _Nullable networkError)
         
            if (result) 
                NSLog(@"%@\n", result);
                //loop all downloaded thumbnails
                for (DBFILESGetThumbnailBatchResultEntry *data in result.entries)
                
                    //extract data from each base64 encoded thumbnail string
                    NSData *thumbData = [[NSData alloc] initWithBase64EncodedString:data.success.thumbnail options:0];
                    //create UIImage from data
                    UIImage *thumbImage = [UIImage imageWithData:thumbData];
                            


            
            else  //if download failed
                NSLog(@"%@\n%@\n", routeError, networkError);
            

【讨论】:

以上是关于使用 getThumbnailBatch 获取 Dropbox 缩略图的主要内容,如果未能解决你的问题,请参考以下文章

在shell中怎么获取当前日期和时间

无法使用 openCv 从 D-Link DCS 932L 获取视频源

js获取当前当前年月日时分秒,以及获取年月日(无时分秒),详情见补充!

获取TypeScript的声明文件.d.ts

linux在shell中获取时间

使用 min 从字典中获取最低键和值 [重复]