2012-08-09 92 views
0

如何使用iOS DropBox SDK将照片上传到DropBox。我曾尝试使用下面的代码尝试:使用Dropbox上传照片iOS SDK

NSData *datobj = UIImagePNGRepresentation(uploadPhoto.image); 
NSString *stringConvertion = [[NSString alloc] initWithData:datobj encoding:NSUTF8StringEncoding]; 
NSString *filename = stringConvertion; 
NSString *destDir = @"/"; 
[[self restClient] uploadFile:filename toPath:destDir 
        withParentRev:nil fromPath:stringConvertion]; 

,但我得到如下回应:[警告] DropboxSDK:文件不存在((空))

回答

1

你正在努力使来自一个字符串图像的PNG数据。请注意,

UIImagePNGRepresentation() 

不返回文件名 - 它返回一个NSData对象,其字节表示原始PNG数据。

试试这个:

NSString *tmpPngFile = [NSTemporaryDirectory() stringByAppendingPathComponent:@"Temp.png"]; 
[UIImagePNGRepresentation(uploadPhoto.image) writeToFile:tmpPngFile atomically:NO]; 
NSString *destDir = @"/"; 
[[self restClient] uploadFile:filename toPath:destDir 
      withParentRev:nil fromPath:tmpPngName];