I am working on the chat app in which I have used the xmpp framework. I am able to send or receive the messages through xmpp. But when I tried to upload the user profile or avatar image with the following code, didn't get success.
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringPath]];
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
UIImageView *thumbimage;
thumbimage.image = tmpImage;
NSData *imageData1 = UIImageJPEGRepresentation(thumbimage.image,0.5);
NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
NSXMLElement *photoXML = [NSXMLElement elementWithName:@"PHOTO"];
NSXMLElement *typeXML = [NSXMLElement elementWithName:@"TYPE" stringValue:@"image/jpeg"];
NSXMLElement *binvalXML = [NSXMLElement elementWithName:@"BINVAL" stringValue:[[NSString alloc] initWithData:imageData1 encoding:NSUTF8StringEncoding]];
[photoXML addChild:typeXML];
[photoXML addChild:binvalXML];
[vCardXML addChild:photoXML];
XMPPvCardTemp *myvCardTemp = [[[self appDelegate] xmppvCardTempModule] myvCardTemp];
if (myvCardTemp) {
[myvCardTemp setPhoto:imageData1];
[[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:myvCardTemp];
}
Please help me to implement the upload image concept to XMPP or correct me If I am doing something wrong in the code.
Thanks in advance.