【问题标题】:Dropbox SDK Chooser download fileDropbox SDK 选择器下载文件
【发布时间】:2015-09-06 13:59:29
【问题描述】:

我想将文件从 Dropbox 下载到我的应用程序中我已经实现了 Dropbox Drop-in API 选择器,因此我被定向到 Dropbox 应用程序并可以选择一个文件,但我不知道如何下载所选文件

- (void)didPressChoose{
[[DBChooser defaultChooser] openChooserForLinkType:DBChooserLinkTypePreview
                                fromViewController:self completion:^(NSArray *results)
 {
     if ([results count]) {
         fileurl = [[results[0] link] absoluteString];
         NSLog(@"got results %@", results);
         NSLog(@"link 0 = %@", [[results[0] link] absoluteString]);
     } else {
         // User canceled the action
     }
 }];

}

我试过这个,但我只得到一个像“dropbox.com/s/2hro2i45h ...”这样的链接,但是对于这个

[self.restClient loadFile:fileurl intoPath:localDir];

我需要类似“/test.txt”的东西

【问题讨论】:

  • 用“link 0 =”打印什么?
  • 文件的链接如:www.dropbox.com/something/file.txt

标签: ios objective-c dropbox-api


【解决方案1】:

首先,documentation for the Dropbox iOS Chooser 列出了两种不同的链接类型。如果你想直接下载文件,你应该使用DBChooserLinkTypeDirect而不是你代码中的DBChooserLinkTypePreview

其次,一旦你有了直接链接,你就可以在链接上使用普通的 HTTP 请求来下载文件内容,例如,使用NSURLRequest。您在代码中使用的loadFile 方法适用于Dropbox iOS Core SDK,如果您只是使用选择器,则不需要使用它。无论如何,该方法不适用于选择器返回的链接。该方法旨在获取用户 Dropbox 帐户中的相对路径,但选择器是一种更简单的集成,只是为您提供了一个链接。

【讨论】:

    【解决方案2】:

    我不确定,但在调用 restClient 上的 loadFile 之前我有这个

    NSString* filePath = [path stringByReplacingOccurrencesOfString:@"dropbox://" withString:@""];
    [restClient loadFile:filePath intoPath:destinationPath];
    

    【讨论】:

    • 这使得:“www.dropbox.com/ugfcfzc76/file.txt”只有“file.txt”这很好,但如果文件在一个文件夹中就不起作用跨度>
    猜你喜欢
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    相关资源
    最近更新 更多