使用DropBox SDK for Iphone从UIImageView上传图像

An1*_*Ba7 0 iphone objective-c dropbox uiimageview ios

我是iOS开发的初学者,刚刚开始使用DropBox SDK for iphone,我目前正在使用MacOSX 10.6版本,其上有Xcode 3.2.5(模拟器为4.2).使用UIImagePickerController,我可以在UIImageView上显示一个选定的图像.现在,如果我想使用DropBox SDK上传该特定图像,我必须知道它在我的应用程序上的路径,因为应用了以下代码

- (void)uploadFile:(NSString*)filename toPath:(NSString*)path fromPath:(NSString *)sourcePath

此方法在DBRestClient.h中定义,该文件来自DropBox SDK for iOS.但是从上面的方法声明中,需要确定UIImageView中存在的图像的"fromPath"以将其上传到我在dropbox上的帐户.能否帮助我确定如何确定路径,或者就此而言,可以适用的任何工作.

Ric*_*III 11

您必须首先将文件写入文件系统:

NSData *data = UIImagePNGRepresentation(imageView.image);
NSString *file = [NSTemporaryDirectory() stringByAppendingPathComponent:@"upload.png"];

[data writeToFile:file atomically:YES];
[DBRestClient uploadFile:@"upload.png" toPath:@"Dropbox/Path" fromPath:file];
Run Code Online (Sandbox Code Playgroud)

请注意,您也可以使用.jpg,更快,更压缩,只需更改UIImagePNGRepresentationUIImageJPEGRepresentation,并传递压缩值(0.8 - 0.9是好的)