我想从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"
这样的东西答案 0 :(得分:1)
首先,documentation for the Dropbox iOS Chooser列出了两种不同的链接类型。如果您想直接下载该文件,则应使用代码中的DBChooserLinkTypeDirect
代替DBChooserLinkTypePreview
。
其次,一旦有了直接链接,就可以在链接上使用普通的HTTP请求来下载文件内容,例如使用NSURLRequest
。您的代码中的loadFile
方法适用于Dropbox iOS Core SDK,如果您只是使用选配器,则不需要使用该方法。无论如何,该方法不适用于Chooser返回的链接。该方法旨在在用户的Dropbox帐户中采用相对路径,但Chooser是一种更简单的集成,只是为您提供链接。
答案 1 :(得分:-2)
我不确定但在调用restClient上的loadFile之前我已经知道了
NSString* filePath = [path stringByReplacingOccurrencesOfString:@"dropbox://" withString:@""];
[restClient loadFile:filePath intoPath:destinationPath];