I am using Dropbox Sync API sdk it display all folder and file but we can not download file i am using this code:
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
I am getting NSData but i can't store in document directory. I check below links but no success
Dropbox Sync API iOS copy files to app documents
Data syncing with DropBox API and iOS
Please Help me.
Dropbox takes time to cache a file, you can set up a block to monitor when the cache is completed:
__block MyViewController *me = self;
[self.dropboxFile addObserver:self block:^() { [me monitorDropboxFile:@"Sync"]; }];
inside the observer:
- (void)monitorDropboxFile:(NSString *)caller
{
if (self.dropboxFile.status.cached) {
; // Good to go, the file is cached
} else {
; // download in progress
}
}
Or, there is a simpler way, use readHandle
:
(DBFile *)file;
// ...
DBError *dbError;
NSFileHandle *fileHandle = [file readHandle:&dbError];
As documented in the Dropbox API header:
/** Returns a read-only file handle for the file. If the file is not cached then the method will block until the file is downloaded.
@return A file handle if the file can be read, ornil
if an error occurred. */
The file handle is ready when returned. However, you might like to put readHandle
in a background thread if the app has to be responsive during file download.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.