Dropbox SDK 选择器下载文件

Dropbox SDK Chooser download file

我想从 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
     }
 }];

}

我试过了,但我只得到一个 link 像 "dropbox.com/s/2hro2i45h ..." 但是对于这个

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

我需要像“/test.txt”这样的东西

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

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

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

其次,一旦你有了直接的 link,你就可以在 link 上使用普通的 HTTP 请求来下载文件内容,例如,使用你没有的 NSURLRequest. The loadFile method you have in your code is for the Dropbox iOS Core SDK如果您只是使用 Chooser,则无需使用。无论如何,该方法不适用于 Chooser 返回的 link。该方法旨在采用用户 Dropbox 帐户中的相对路径,但选择器是一个更简单的集成,它只为您提供 link。