python-wechaty icon indicating copy to clipboard operation
python-wechaty copied to clipboard

⁉ ⁉如何获取消息中的文件大小

Open 17186765070 opened this issue 2 years ago • 3 comments

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

17186765070 avatar Mar 28 '22 04:03 17186765070

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.

wj-Mcat avatar Apr 02 '22 11:04 wj-Mcat

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 avatar Apr 12 '22 06:04 17186765070

@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.

wj-Mcat avatar Apr 12 '22 23:04 wj-Mcat