0

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

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:文件不存在((null))

4

1 回答 1

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];
于 2012-08-09T12:51:06.823 回答