在base64编码字符串中将图像上载到服务器时出错

时间:2011-08-12 07:11:41

标签: iphone objective-c xcode asihttprequest

我正在尝试将数据上传到服务器上。服务器可以接受图像串。现在我使用以下代码将图像上传到服务器。

NSData *image = UIImagePNGRepresentation(image);
NSString* pictureDataString = [image base64EncodingWithLineLength:0];
[_request setPostValue:pictureDataString forKey:@"media"];

但我收到以下错误。任何人都可以帮助我。

"(<class 'google.appengine.api.datastore_errors.BadValueError'>, BadValueError('Property media must be convertible to a Blob instance (Blob() argument should be str instance, not unicode)',), <traceback object at 0x69a1cd63d506f800>)"

1 个答案:

答案 0 :(得分:0)

只需使用..

    NSData *image = UIImagePNGRepresentation(image);
    [_request setPostValue:image for key:"media";

它会起作用。