如何将 iPhone 中的照片 (PHAsset) 放入 Dropbox?

How to put photos (PHAsset) in an iPhone to Dropbox?

我正在尝试使用 Dropbox API 将我的照片放入 iPhone,但是当我使用此代码时:

                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];
            }];

它告诉我一个错误 "files does not exist : /var/mobile/Media/DCIM/101APPLE/IMG_1080.PNG"

我不明白为什么?! 在 Dropbox 中检索和存储我的视频的正确路径是什么?

没有看到更多的代码,我能想到的最好的是它与以下两件事之一有关:

声明后某处路径错误fileName;尝试:

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];

或者,如果这不起作用,则可能与 PHAsset 的不变性有关。尝试改为复制到临时文件夹:

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];