Reputation: 707
I am new to iOS and trying to use the dropbox core API:
1) Download a file from dropbox
2) Collect the file from the folder it was saved and show it onscreen
The rest client claims the file loads successfully, but when I try to access it, it does not seem to exist. Here is what I'm doing:
Create directory locally and load the photos:
- (void)initDBPHotos
{
NSString *directory = @"lobyPhotos";
[self createDirecotry:directory];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:directory];
for (DBMetadata *file in self.metaData.contents) {
[self.restClient loadFile:file.path intoPath:fullPath];
}
[self loadPhotoArray:fullPath];
}
Create the directory:
- (void)createDirecotry:(NSString *)dirName
{
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:dirName];
NSError *error;
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
if (![[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:NO
attributes:nil
error:&error])
{
NSLog(@"Create directory error: %@", error);
}
}
}
The restClient file loaded success method:
- (void)restClient:(DBRestClient *)client loadedFile:(NSString *)localPath
contentType:(NSString *)contentType metadata:(DBMetadata *)metadata {
NSLog(@"File loaded into path: %@", localPath);
int numFiles = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:localPath error:nil] count];
NSLog(@"There are %d files in the local path", numFiles);
}
The result of this log is always 0 event though the loadedFile method always fires saying that it successfully loaded the file to the given path.
Upvotes: 0
Views: 231
Reputation: 318874
The problem is with this line:
[self.restClient loadFile:file.path intoPath:fullPath];
Your fullPath
isn't really a full path, it is a reference to a folder. You need to give an actual full path.
Try this:
for (DBMetadata *file in self.metaData.contents) {
NSString *filename = [file.path lastPathComponent];
NSString *destPath = [fullPath stringByAppendingPathComponent:filename];
[self.restClient loadFile:file.path intoPath:destPath];
}
Also be sure that the lobyPhotos
folder has already been created inside the Documents
folder.
Upvotes: 1