wechaty / puppet-wechat

Wechaty Puppet Provider for WeChat
https://www.npmjs.com/package/wechaty-puppet-wechat
Apache License 2.0
419 stars 71 forks source link

Cannot download file to local #194

Closed xiaogaozi closed 2 years ago

xiaogaozi commented 2 years ago

When receiving messages from other people about files (including images, videos, attachments, etc.), downloading to local disk using the FileBox.toFile() API always results in a file size of 0.

This issue was only recently discovered, and was only occasionally occurring before, but is now 100% reproduced.

Some context:

shangdev commented 2 years ago

回退到版本 0.27.0 后,也发现这个问题。

"dependencies": {
  "gerror": "^1.0.16",
  "wechaty": "^0.68.1",
  "wechaty-puppet-wechat": "0.27.0"
}

打印 FileBox 信息: image

其中 remoteUrl 也可以点击访问,但是下单后的文件依然是 0 kb。

huan commented 2 years ago

Please try the latest version of wechaty-puppet-wechat@1.11.9+ and let me know if this problem exists in the latest version.

pacoyang commented 2 years ago

Please try the latest version of wechaty-puppet-wechat@1.11.9+ and let me know if this problem exists in the latest version.

@huan The fix version should be wechaty-puppet-wechat@1.11.10+ 🤔️ Users using version 0.x but do not want to upgrade to 1.x can rebuild FileBox to solve this problem:

const box = await msg.toFileBox()
const newBox = FileBox.fromUrl(box.remoteUrl.replace(/^http/i, 'https'), box.name, {
  ...box.headers,
  Referer: box.headers.Referer.replace(/^http/i, 'https'),
})
huan commented 2 years ago

Awesome, your workaround is very smart!

Thank you very much for helping the community to fix the bug and confirm it works, appreciate it!

Close this issue because it has been fixed by @pacoyang

shangdev commented 2 years ago

@pacoyang 请问对应的 wechaty 版本是多少呢?

pacoyang commented 2 years ago

@pacoyang 请问对应的 wechaty 版本是多少呢?

这个 issue 跟 wechaty 版本没有联系,可以用最新的 wechaty@1.10.4