1

I am posting data to a server from my ipad using json. But along with my data, i need to be able to send images aswell. I tried to add my image data to a dictionary and parse that into json, but json doesnt like nscfdata. What would be the easiest way i can post my images to the server? from other posts related to this topic, people have been converting to base64. Would i have to do that, or is there another easier or faster way? if i have to encode to base64 is there any tutorial on that?

hamza h
  • 355
  • 1
  • 4
  • 12

1 Answers1

6

I convert it to base64. Check out this tutorial to get started!

http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html

Example:

NSImage *image = // some image
NSData *data = UIImagePNGRepresentation(image);
NSString *base64EncodedString = [data base64EncodedString];

You can then send the string via JSON.

rocky
  • 3,521
  • 1
  • 23
  • 31