【问题标题】:How to put photos (PHAsset) in an iPhone to Dropbox?如何将 iPhone 中的照片(PHAsset)放入 Dropbox?
【发布时间】:2015-08-21 17:19:35
【问题描述】:

我正在尝试使用 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];
            }];

我有一个错误告诉我“文件不存在:/var/mobile/Media/DCIM/101APPLE/IMG_1080.PNG”

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

【问题讨论】:

  • 是的,但我的代码在模拟器上运行良好,而在 iPhone 上则不行。
  • 如果不了解您是如何检索资产的(使用 PHAsset 或 ALAssetsLibrary),真的很难说为什么找不到确切的图像。
  • 抱歉,lastAsset 是一个 PHAsset。我总是使用 PHAsset。
  • 你能在里面添加那个代码吗?看起来 lastAsset 可能根本不起作用。
  • 这部分在另一个文件中,在 Swift 中 let fetchResult = PHAsset.fetchAssetsWithMediaType(PHAssetMediaType.Image, options: fetchOptionsImage) 之后,我通过一个 segue 传递 fetchResult 数组,而 lastAsset 是一个对象fetchResult 数组。

标签: ios objective-c iphone assets dropbox-api


【解决方案1】:

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

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

【讨论】:

  • 非常感谢!!第一个解决方案不起作用,但第二个是!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多