【问题标题】:How to download file from dropbox using Dropbox Sync API iOS SDK如何使用 Dropbox Sync API iOS SDK 从 Dropbox 下载文件
【发布时间】:2013-09-27 11:34:15
【问题描述】:

我正在使用Dropbox Sync API sdk 它显示所有文件夹和文件但我们无法下载文件 我正在使用此代码:

  DBFilesystem *filesystem;
  DBFile *file = [_filesystem openFile:info.path error:nil];
   NSData *imagedata=[file readData:nil];
  [fileMan createFileAtPath:Image_filePath  contents:**data** attributes:nil];
  NSLog(@"flao=%d",[file writeData:imagedata error:nil]);
  // it return 1

我正在获取 NSData,但我无法存储在文档目录中。 我检查了以下链接,但没有成功

Dropbox Sync API iOS copy files to app documents

Data syncing with DropBox API and iOS

请帮帮我。

【问题讨论】:

  • 你实现了下面的函数吗,你在下面的方法中得到任何值吗我的朋友??? - (void)restClient:(DBRESTClient *)client loadedMetadata:(DBMetadata *)metadata { }
  • @NiravPatel restclient 是核心 api 功能,因此同步应用程序中允许使用此功能
  • 尝试检查错误。 NSError *error; NSData *imagedata = [file readData:&error]; if (error) NSLog(@"%@", error.localizedDescription);

标签: iphone ios objective-c dropbox


【解决方案1】:

Dropbox需要时间来缓存文件,你可以设置一个块来监控缓存何时完成:

__block MyViewController *me = self;
[self.dropboxFile addObserver:self block:^() { [me monitorDropboxFile:@"Sync"]; }];

观察者内部:

- (void)monitorDropboxFile:(NSString *)caller
{
    if (self.dropboxFile.status.cached) {
        ; // Good to go, the file is cached
    } else {
        ; // download in progress
    }
}

或者,还有更简单的方法,使用readHandle

(DBFile *)file;
// ...  
DBError *dbError;
NSFileHandle *fileHandle = [file readHandle:&dbError];

如 Dropbox API 标头中所述:

/** 返回文件的只读文件句柄。如果文件不是 缓存然后该方法将阻塞,直到文件被下载。
@return 如果文件可以读取,则返回文件句柄,如果出现错误,则返回 nil 发生了。 */

文件句柄在返回时准备就绪。但是,如果应用必须在文件下载期间做出响应,您可能希望将 readHandle 放在后台线程中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-30
    • 1970-01-01
    相关资源
    最近更新 更多