python-wechaty
python-wechaty copied to clipboard
⁉ ⁉如何获取消息中的文件大小
requirements
- token type [paimon]
- version of python-wechaty [0.8.33]
Describe your problem
如何获取消息中的文件大小,通过如下方式可以获取文件名称,如何获取文件大小呢?谢谢帮助
Reproduce your problem
if msg.type() == MessageType.MESSAGE_TYPE_ATTACHMENT:
file_src = msg.payload.filename
There are different types of files, eg: Url, Stream, Base64 and Local file. There is a simple way for you to get the size of file:
# step 1
file = file_box.to_file()
# step 2
file_size = os.path.getsize('d:/file.jpg')
print("File Size is :", file_size, "bytes")
Hope it can help you fix your problem.
Thank you for your reply @wj-Mcat
If I use to_ File() ,One of the problems I encounter now is that if the file is too large, the program will fail.
Therefore, I want to get the file size first. If it exceeds 2m, then I decide not to file_box.to_file() the file
@17186765070 yes, I’m sorry to say that there are some issues when solving big files, but we will fix it in next few days. You can keep eyes on this issue to get latest progress.