I am trying to put my photos in my iPhone with Dropbox API, but when I use this code :
mimeType = @".png";
[[PHImageManager defaultManager]requestImageForAsset:lastAsset targetSize:size contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage* result, NSDictionary* info){
fileName = [lastAsset.creationDate.description substringWithRange:NSMakeRange(0, lastAsset.creationDate.description.length-6)];
data = UIImagePNGRepresentation(imageView.image);
NSString* imagePath = [[info objectForKey:@"PHImageFileURLKey"]absoluteString];
NSString* fImagePath = [imagePath substringFromIndex:7];
[dbRestClient uploadFile:[NSString stringWithFormat:@"%@%@",fileName,mimeType] toPath:@"/" withParentRev:nil fromPath:fImagePath];
}];
I have an error which it tells to me "files does not exist : /var/mobile/Media/DCIM/101APPLE/IMG_1080.PNG"
I don't understand why ?! What is the correct path to retrieve and store my videos in Dropbox ?
Without seeing more code, the best I can come up with is that it's related to one of two things:
Bad paths somewhere after you declare fileName
; try:
fileName = [lastAsset.creationDate.description substringWithRange:NSMakeRange(0, lastAsset.creationDate.description.length-6)];
NSString* imagePath = [[info objectForKey:@"PHImageFileURLKey"]absoluteString];
[dbRestClient uploadFile:fileName toPath:@"/" withParentRev:nil fromPath:imagePath];
Or, if that doesn't work, then it might be related to the immutability of PHAsset
. Try instead copying to a temp folder:
fileName = [lastAsset.creationDate.description substringWithRange:NSMakeRange(0, lastAsset.creationDate.description.length-6)];
NSString *tmp = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
NSData *data = UIImageJPGRepresentation(result);
[data writeToFile:tmp atomically:YES]; // you might need UIImagePNGRepresentation here as well
[self.dropboxClient uploadFile:fileName toPath:destDir withParentRev:nil fromPath:tmp];