I am using XMPP framework on iPhone for my chatting application. I want to send image from my app using the XMPP framework. Can anyone suggest me, how to do this?
Any help would be appreciated.
I am using XMPP framework on iPhone for my chatting application. I want to send image from my app using the XMPP framework. Can anyone suggest me, how to do this?
Any help would be appreciated.
Add an extra tag such as
<attachment>base64 of your image </attachment>
Thus sent your image in the sender side by converting it to base64 string and convert the base64 string back into image in the receiver side.
Just convert the Uiimage into a base64encoded coding and then sent it through xmpp as a message with any extra tag like attachement.. Then in the receiver side get the message with the base64 content and convert back the base64encoded string into UIImage
The code for encode and decode is in this link :
http://iphonesdksnippets.com/post/2010/03/14/Convert-image-tofrom-text-%28Base64%29.aspx
... Just refer it.. If you have any doubt or you want a brief explanation, just comment here i will respond to it..
NSData *data = UIImageJPEGRepresentation(chosenImage, 1.0);
Base64Transcoder *base64 = [[Base64Transcoder alloc] init];
NSString *imgStr = [base64 base64EncodedStringfromData:data];
NSXMLElement *ImgAttachement = [NSXMLElement elementWithName:@"attachment"];
[ImgAttachement setStringValue:imgStr];
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:@"image test"];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:@"13iapp@jabbim.cz"];// [NSString stringWithFormat:@"%@@192.168.1.193",self.jabber_id]];
[message addChild:message];
[message addChild:ImgAttachement];
[[[PDAppDelegate sharedDelegate] xmppStream]sendElement:message];
Either put the file to a WebDAV server and send the URL over XMPP, use XEP-0065, or XEP-0047. Many who ask this question choose XEP-47, but that is almost always the wrong choice unless the files are very small, since many servers will penalize your connection as a potential denial of service for sending large amounts of data.