ItChat icon indicating copy to clipboard operation
ItChat copied to clipboard

upload file 支持 filelike-object

Open AZLisme opened this issue 9 years ago • 3 comments

目前的upload_file只支持文件目录上传,对于储存在内存中的数据上传则不支持(例如BytesIO),希望能将fileDir参数扩展到支持广泛的file-like object,直接使用read()读取数据

AZLisme avatar Mar 22 '17 02:03 AZLisme

@AZLisme 好,1.3.0里面我会增加这个功能。

littlecodersh avatar Mar 22 '17 07:03 littlecodersh

@AZLisme 已更新,你可以在这里看到最新的commit。

下面是测试程序:

import itchat

itchat.auto_login(True)

with open('t.pdf', 'rb') as f:
    r = itchat.send_file('test.pdf', 'filehelper', file_=f)
# equals to:
# r = itchat.send_file('t.pdf', 'filehelper')
print(r)

with open('t.png', 'rb') as f:
    r = itchat.send_image(f, 'filehelper')
# equals to:
# r = itchat.send_image('t.png', 'filehelper')
print(r)

with open('t.mp4', 'rb') as f:
    r = itchat.send_video(f, 'filehelper')
# equals to:
# r = itchat.send_video('t.mp4', 'filehelper')
print(r)

itchat.run()

littlecodersh avatar Mar 22 '17 09:03 littlecodersh

👍

AZLisme avatar Mar 22 '17 09:03 AZLisme