2012-08-09 127 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];