2015-09-06 125 views
-1

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

- (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

用“link 0 =”打印什么? – akashsr

+0

链接到文件如:www.dropbox.com/something/file.txt – Maximilian

回答

1

首先,documentation for the Dropbox iOS Chooser列出两种不同的链接类型之前都没有了。如果你想直接下载文件,你应该使用DBChooserLinkTypeDirect而不是像你的代码那样使用DBChooserLinkTypePreview。其次,如果您有直接链接,则可以在链接上使用正常的HTTP请求来下载文件内容,例如使用NSURLRequest。您在代码中使用的loadFile方法适用于Dropbox iOS Core SDK,如果您只是使用选配器,则不需要使用该方法。无论如何,该方法不适用于Chooser返回的链接。该方法旨在在用户的Dropbox帐户中使用相对路径,但Chooser是一个更简单的集成,它只是为您提供链接。

+0

工作感谢您 – Maximilian

-1

我不知道,但我打电话的loadFile上RESTClient实现

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

这使得这个:“www.dropbox.com/ugfcfzc76/file.txt”只有“file.txt”多数民众赞成在良好的但如果文件位于不起作用的文件夹中 – Maximilian