使用Python开发,用的cython
获取媒体文件相关代码:
if content.get("msgtype") == "image":
print(content)
image_data = content["image"]
sdkFileid = image_data["sdkfileid"]
is_finish = 0
# index_buf = b"Range:bytes=0-100"
index_buf = b""
while is_finish == 0:
m_data = NewMediaData()
tmp_ret = GetMediaData(sdk, index_buf, sdkFileid.encode(), b"", b"", 30, m_data)
if tmp_ret != 0:
print("GetMediaData 错误 %s" % tmp_ret)
FreeMediaData(m_data)
return
data = GetData(m_data)
is_finish = IsMediaDataFinish(m_data)
index_buf = GetOutIndexBuf(m_data)
data_len = GetDataLen(m_data)
print("size %s, next_index_buf %s, is_finish %s" % (data_len, index_buf, is_finish))
FreeMediaData(m_data)
运行结果如下:
{'msgid': '17255191468933074503_1639450740150_external', 'action': 'send', 'from': '隐藏隐藏', 'tolist': ['隐藏隐藏'], 'roomid': '', 'msgtime': 1639450739990, 'msgtype': 'image', 'image': {'md5sum': '869775cdcef8d4d0291b17fb04ff8889', 'filesize': 77368, 'sdkfileid': 'CiA4YzkxZWUwNGUyNmYwYTE2NGI3YWMxNjAzZmJlZTAwMRI4TkRkZk56ZzRNVE13TVRBd01Ua3hNVEF5TWw4eE1UZ3pNalV3TVRReVh6RTJNemswTlRBM05EQT0aIDZmZWQzNWMyZWI1MDFjOTY3ZmNmMmM0ZWY1ZDFjNzdm'}}
size 77368, next_index_buf b'', is_finish 1
然后文件内容也只有小部分
文件内容 : b'\xff\xd8\xff\xe0'
明显没有'filesize': 77368 这么大