hamza h
hamza h

Reputation: 395

sending images to server via json

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?

Upvotes: 1

Views: 2543

Answers (1)

rocky
rocky

Reputation: 3541

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.

Upvotes: 6

Related Questions