Search code examples
iphoneobjective-cxcodeasihttprequest

Error while uploading image to server in base 64encoding string


I'm trying to upload data onto a server. The server can accept strings of images. Now I'm using the following code to upload image to the server.

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

But I'm getting the following error. Can anyone please help me out here.

"(<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>)"

Solution

  • just use..

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

    it will work.