Hi all:
Is it possible to send images (or other binary files) via pjsip instant messaging using pjsua2? I am using pjsip 2.7.1.
I can IM text messages fine, but when I try and send a binary file I get err=171023 (Message too long (PJSIP_EMSGTOOLONG))
I read the FAQ and did quite a bit of searching, so hopefully I'm not missing anything obvious.
Here is the python method I am using:
def send_file(self, buddy, file_path):
'''sends file via sip IM'''
(mime_type, mime_encoding) = mimetypes.guess_type(file_path)
self._logger.debug('mime_type = %s', mime_type)
self._logger.debug('mime_encoding = %s', mime_encoding)
if mime_type is None:
self._logger.debug('could not determine mime type for file %s', file_path)
else:
with open(file_path, 'rb') as file_reader:
file_contents_bytes = file_reader.read()
file_reader.close()
self._logger.debug('len(file_contents_bytes) = %s', file_contents_bytes)
base64_data = codecs.encode(file_contents_bytes, 'base64')
string_data = base64_data.decode('utf-8')
send_im_param = pj.SendInstantMessageParam()
send_im_param.content = string_data
send_im_param.contentType = mime_type
buddy.sendInstantMessage(send_im_param)
self._logger.debug("sent binary instant msg with length %d to %s", len(file_contents_bytes), str(buddy))
buddy = None
self._logger.debug('buddy set to None')
And here is a snip from the pj sip logs (I can post the entire log if desired)
begin log snip
08:28:47.195 endpoint Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8) created.
08:28:47.195 tsx0x1ab82a8 .Transaction created for Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8)
08:28:47.195 tsx0x1ab82a8 Sending Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8) in state Null
08:28:47.195 sip_resolve.c .Target '192.168.2.102:0' type=Unspecified resolved to '192.168.2.102:5060' type=UDP (UDP transport)
08:28:47.195 tsx0x1ab82a8 .Failed to send Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8)! err=171023 (Message too long (PJSIP_EMSGTOOLONG))
08:28:47.195 tsx0x1ab82a8 .State changed from Null to Terminated, event=TRANSPORT_ERROR
08:28:47.195 pjsua_im.h ..Failed to deliver message '[removed long base 64 string]
08:28:47.222 pjsua_im.h Unable to send request: Message too long (PJSIP_EMSGTOOLONG) [status=171023]
08:28:47.222 presence.cpp pjsua_im_send(acc->getId(), &to, &mime_type, &content, &msg_data, user_data) error: Message too long (PJSIP_EMSGTOOLONG) (status=171023) [../src/pjsua2/presence.cpp:172]
Thank you in advance for any help.
Is it possible to send images (or other binary files) via pjsip instant messaging using pjsua2? I am using pjsip 2.7.1.
I can IM text messages fine, but when I try and send a binary file I get err=171023 (Message too long (PJSIP_EMSGTOOLONG))
I read the FAQ and did quite a bit of searching, so hopefully I'm not missing anything obvious.
Here is the python method I am using:
def send_file(self, buddy, file_path):
'''sends file via sip IM'''
(mime_type, mime_encoding) = mimetypes.guess_type(file_path)
self._logger.debug('mime_type = %s', mime_type)
self._logger.debug('mime_encoding = %s', mime_encoding)
if mime_type is None:
self._logger.debug('could not determine mime type for file %s', file_path)
else:
with open(file_path, 'rb') as file_reader:
file_contents_bytes = file_reader.read()
file_reader.close()
self._logger.debug('len(file_contents_bytes) = %s', file_contents_bytes)
base64_data = codecs.encode(file_contents_bytes, 'base64')
string_data = base64_data.decode('utf-8')
send_im_param = pj.SendInstantMessageParam()
send_im_param.content = string_data
send_im_param.contentType = mime_type
buddy.sendInstantMessage(send_im_param)
self._logger.debug("sent binary instant msg with length %d to %s", len(file_contents_bytes), str(buddy))
buddy = None
self._logger.debug('buddy set to None')
And here is a snip from the pj sip logs (I can post the entire log if desired)
begin log snip
08:28:47.195 endpoint Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8) created.
08:28:47.195 tsx0x1ab82a8 .Transaction created for Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8)
08:28:47.195 tsx0x1ab82a8 Sending Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8) in state Null
08:28:47.195 sip_resolve.c .Target '192.168.2.102:0' type=Unspecified resolved to '192.168.2.102:5060' type=UDP (UDP transport)
08:28:47.195 tsx0x1ab82a8 .Failed to send Request msg MESSAGE/cseq=1084 (tdta0x1adf3a8)! err=171023 (Message too long (PJSIP_EMSGTOOLONG))
08:28:47.195 tsx0x1ab82a8 .State changed from Null to Terminated, event=TRANSPORT_ERROR
08:28:47.195 pjsua_im.h ..Failed to deliver message '[removed long base 64 string]
08:28:47.222 pjsua_im.h Unable to send request: Message too long (PJSIP_EMSGTOOLONG) [status=171023]
08:28:47.222 presence.cpp pjsua_im_send(acc->getId(), &to, &mime_type, &content, &msg_data, user_data) error: Message too long (PJSIP_EMSGTOOLONG) (status=171023) [../src/pjsua2/presence.cpp:172]
Thank you in advance for any help.
_______________________________________________ Visit our blog: http://blog.pjsip.org pjsip mailing list pjsip@xxxxxxxxxxxxxxx http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org